removed the mutex locks with atomic bool (#6525)
Signed-off-by: Jeffrey Damick <jdamick@amazon.com> Co-authored-by: Jeffrey Damick <jdamick@amazon.com>
This commit is contained in:
parent
8868454177
commit
b2defec33a
1 changed files with 5 additions and 13 deletions
|
@ -13,7 +13,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
golog "log"
|
golog "log"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
// D controls whether we should output debug logs. If true, we do, once set
|
// D controls whether we should output debug logs. If true, we do, once set
|
||||||
|
@ -21,30 +21,22 @@ import (
|
||||||
var D = &d{}
|
var D = &d{}
|
||||||
|
|
||||||
type d struct {
|
type d struct {
|
||||||
on bool
|
on atomic.Bool
|
||||||
sync.RWMutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set enables debug logging.
|
// Set enables debug logging.
|
||||||
func (d *d) Set() {
|
func (d *d) Set() {
|
||||||
d.Lock()
|
d.on.Store(true)
|
||||||
d.on = true
|
|
||||||
d.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear disables debug logging.
|
// Clear disables debug logging.
|
||||||
func (d *d) Clear() {
|
func (d *d) Clear() {
|
||||||
d.Lock()
|
d.on.Store(false)
|
||||||
d.on = false
|
|
||||||
d.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value returns if debug logging is enabled.
|
// Value returns if debug logging is enabled.
|
||||||
func (d *d) Value() bool {
|
func (d *d) Value() bool {
|
||||||
d.RLock()
|
return d.on.Load()
|
||||||
b := d.on
|
|
||||||
d.RUnlock()
|
|
||||||
return b
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// logf calls log.Printf prefixed with level.
|
// logf calls log.Printf prefixed with level.
|
||||||
|
|
Loading…
Add table
Reference in a new issue