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 (
|
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)
|
stderrColoredOutput = ansicolor.NewAnsiColorWriter(os.Stderr)
|
||||||
|
|
||||||
@@ -198,12 +201,11 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// wrap around standard fmt functions
|
// wrap around standard fmt functions
|
||||||
// consolePrint prints a message prefixed with message type and program name
|
// consolePrint prints a message prefixed with message type and program name
|
||||||
consolePrint = func(tag string, c *color.Color, a ...interface{}) {
|
func consolePrint(tag string, c *color.Color, a ...interface{}) {
|
||||||
mutex.Lock()
|
privateMutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer privateMutex.Unlock()
|
||||||
|
|
||||||
switch tag {
|
switch tag {
|
||||||
case "Debug":
|
case "Debug":
|
||||||
@@ -248,9 +250,9 @@ var (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// consolePrintf - same as print with a new line
|
// consolePrintf - same as print with a new line
|
||||||
consolePrintf = func(tag string, c *color.Color, format string, a ...interface{}) {
|
func consolePrintf(tag string, c *color.Color, format string, a ...interface{}) {
|
||||||
mutex.Lock()
|
privateMutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer privateMutex.Unlock()
|
||||||
|
|
||||||
switch tag {
|
switch tag {
|
||||||
case "Debug":
|
case "Debug":
|
||||||
@@ -295,9 +297,9 @@ var (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// consolePrintln - same as print with a new line
|
// consolePrintln - same as print with a new line
|
||||||
consolePrintln = func(tag string, c *color.Color, a ...interface{}) {
|
func consolePrintln(tag string, c *color.Color, a ...interface{}) {
|
||||||
mutex.Lock()
|
privateMutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer privateMutex.Unlock()
|
||||||
|
|
||||||
switch tag {
|
switch tag {
|
||||||
case "Debug":
|
case "Debug":
|
||||||
@@ -340,22 +342,21 @@ var (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
// Lock console
|
// Lock console
|
||||||
func Lock() {
|
func Lock() {
|
||||||
mutex.Lock()
|
publicMutex.Lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock locked console
|
// Unlock locked console
|
||||||
func Unlock() {
|
func Unlock() {
|
||||||
mutex.Unlock()
|
publicMutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCustomTheme sets a color theme
|
// SetCustomTheme sets a color theme
|
||||||
func SetCustomTheme(theme map[string]*color.Color) *probe.Error {
|
func SetCustomTheme(theme map[string]*color.Color) *probe.Error {
|
||||||
mutex.Lock()
|
privateMutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer privateMutex.Unlock()
|
||||||
// add new theme
|
// add new theme
|
||||||
for k, v := range theme {
|
for k, v := range theme {
|
||||||
Theme[k] = v
|
Theme[k] = v
|
||||||
@@ -371,7 +372,7 @@ func ProgramName() string {
|
|||||||
|
|
||||||
// SetNoColor disable coloring
|
// SetNoColor disable coloring
|
||||||
func SetNoColor() {
|
func SetNoColor() {
|
||||||
mutex.Lock()
|
privateMutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer privateMutex.Unlock()
|
||||||
color.NoColor = true
|
color.NoColor = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,3 +35,18 @@ func (s *MySuite) TestSetTheme(c *C) {
|
|||||||
_, ok := Theme["unknown"]
|
_, ok := Theme["unknown"]
|
||||||
c.Assert(ok, Equals, true)
|
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