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:
jdamick 2024-03-06 13:57:12 -05:00 committed by GitHub
parent 8868454177
commit b2defec33a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,7 +13,7 @@ import (
"io"
golog "log"
"os"
"sync"
"sync/atomic"
)
// D controls whether we should output debug logs. If true, we do, once set
@ -21,30 +21,22 @@ import (
var D = &d{}
type d struct {
on bool
sync.RWMutex
on atomic.Bool
}
// Set enables debug logging.
func (d *d) Set() {
d.Lock()
d.on = true
d.Unlock()
d.on.Store(true)
}
// Clear disables debug logging.
func (d *d) Clear() {
d.Lock()
d.on = false
d.Unlock()
d.on.Store(false)
}
// Value returns if debug logging is enabled.
func (d *d) Value() bool {
d.RLock()
b := d.on
d.RUnlock()
return b
return d.on.Load()
}
// logf calls log.Printf prefixed with level.