mirror of
https://github.com/minio/mc.git
synced 2025-11-12 01:02:26 +03:00
separate mutex for internal and external locking
This commit is contained in:
committed by
Harshavardhana
parent
942a633c67
commit
3a9b2064f6
@@ -53,7 +53,10 @@ var Theme = map[string]*color.Color{
|
||||
}
|
||||
|
||||
var (
|
||||
mutex = &sync.RWMutex{}
|
||||
// Used by the caller to print multiple lines atomically. Exposed by Lock/Unlock methods.
|
||||
publicMutex = &sync.Mutex{}
|
||||
// Used internally by console.
|
||||
privateMutex = &sync.Mutex{}
|
||||
|
||||
stderrColoredOutput = ansicolor.NewAnsiColorWriter(os.Stderr)
|
||||
|
||||
@@ -198,12 +201,11 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
// wrap around standard fmt functions
|
||||
// consolePrint prints a message prefixed with message type and program name
|
||||
consolePrint = func(tag string, c *color.Color, a ...interface{}) {
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
func consolePrint(tag string, c *color.Color, a ...interface{}) {
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
|
||||
switch tag {
|
||||
case "Debug":
|
||||
@@ -248,9 +250,9 @@ var (
|
||||
}
|
||||
|
||||
// consolePrintf - same as print with a new line
|
||||
consolePrintf = func(tag string, c *color.Color, format string, a ...interface{}) {
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
func consolePrintf(tag string, c *color.Color, format string, a ...interface{}) {
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
|
||||
switch tag {
|
||||
case "Debug":
|
||||
@@ -295,9 +297,9 @@ var (
|
||||
}
|
||||
|
||||
// consolePrintln - same as print with a new line
|
||||
consolePrintln = func(tag string, c *color.Color, a ...interface{}) {
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
func consolePrintln(tag string, c *color.Color, a ...interface{}) {
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
|
||||
switch tag {
|
||||
case "Debug":
|
||||
@@ -340,22 +342,21 @@ var (
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// Lock console
|
||||
func Lock() {
|
||||
mutex.Lock()
|
||||
publicMutex.Lock()
|
||||
}
|
||||
|
||||
// Unlock locked console
|
||||
func Unlock() {
|
||||
mutex.Unlock()
|
||||
publicMutex.Unlock()
|
||||
}
|
||||
|
||||
// SetCustomTheme sets a color theme
|
||||
func SetCustomTheme(theme map[string]*color.Color) *probe.Error {
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
// add new theme
|
||||
for k, v := range theme {
|
||||
Theme[k] = v
|
||||
@@ -371,7 +372,7 @@ func ProgramName() string {
|
||||
|
||||
// SetNoColor disable coloring
|
||||
func SetNoColor() {
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
color.NoColor = true
|
||||
}
|
||||
|
||||
@@ -35,3 +35,18 @@ func (s *MySuite) TestSetTheme(c *C) {
|
||||
_, ok := Theme["unknown"]
|
||||
c.Assert(ok, Equals, true)
|
||||
}
|
||||
|
||||
func (s *MySuite) TestLock(c *C) {
|
||||
Lock()
|
||||
Print("") // Test for deadlocks.
|
||||
Unlock()
|
||||
}
|
||||
|
||||
func (s *MySuite) TestTesting(c *C) {
|
||||
// Enable testing
|
||||
IsTesting = true
|
||||
Fatalln("THIS IS A TEST MESSAGE. PLEASE INGORE.")
|
||||
c.Assert(IsExited, Equals, true)
|
||||
// reset back
|
||||
IsExited = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user