diff options
author | 2024-03-06 13:57:12 -0500 | |
---|---|---|
committer | 2024-03-06 13:57:12 -0500 | |
commit | b2defec33a757c4f929b3d3705c3ec71ef2872b1 (patch) | |
tree | 29a34aa9f7307c49d064d3fe79b9f57839215567 | |
parent | 8868454177bdd3e70e71bd52d3c0e38bcf0d77fd (diff) | |
download | coredns-b2defec33a757c4f929b3d3705c3ec71ef2872b1.tar.gz coredns-b2defec33a757c4f929b3d3705c3ec71ef2872b1.tar.zst coredns-b2defec33a757c4f929b3d3705c3ec71ef2872b1.zip |
removed the mutex locks with atomic bool (#6525)
Signed-off-by: Jeffrey Damick <jdamick@amazon.com>
Co-authored-by: Jeffrey Damick <jdamick@amazon.com>
-rw-r--r-- | plugin/pkg/log/log.go | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/plugin/pkg/log/log.go b/plugin/pkg/log/log.go index 0589a3457..ad8d7ac3d 100644 --- a/plugin/pkg/log/log.go +++ b/plugin/pkg/log/log.go @@ -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. |