diff options
| author | Prabhav Dogra <prabhavdogra1@gmail.com> | 2025-04-20 07:52:58 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-04-22 08:28:13 -0700 |
| commit | 95611c0eb4436102ab0dad3a705acff5f5eb7aca (patch) | |
| tree | a7be0ceeb1039666a5f79dab0093c5cd5b89a3e4 /src/sync | |
| parent | 352dd2d932c1c1c6dbc3e112fcdfface07d4fffb (diff) | |
| download | go-95611c0eb4436102ab0dad3a705acff5f5eb7aca.tar.xz | |
sync: use atomic.Bool for Once.done
Updated the use of atomic.Uint32 to atomic.Bool for sync package.
Change-Id: Ib8da66fea86ef06e1427ac5118016b96fbcda6b1
GitHub-Last-Rev: d36e0f431fcde988f90badf86bbf04a18a411947
GitHub-Pull-Request: golang/go#73447
Reviewed-on: https://go-review.googlesource.com/c/go/+/666895
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
Diffstat (limited to 'src/sync')
| -rw-r--r-- | src/sync/once.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/sync/once.go b/src/sync/once.go index 90840b19b5..1573b28b28 100644 --- a/src/sync/once.go +++ b/src/sync/once.go @@ -25,7 +25,7 @@ type Once struct { // The hot path is inlined at every call site. // Placing done first allows more compact instructions on some architectures (amd64/386), // and fewer instructions (to calculate offset) on other architectures. - done atomic.Uint32 + done atomic.Bool m Mutex } @@ -64,7 +64,7 @@ func (o *Once) Do(f func()) { // This is why the slow path falls back to a mutex, and why // the o.done.Store must be delayed until after f returns. - if o.done.Load() == 0 { + if !o.done.Load() { // Outlined slow-path to allow inlining of the fast-path. o.doSlow(f) } @@ -73,8 +73,8 @@ func (o *Once) Do(f func()) { func (o *Once) doSlow(f func()) { o.m.Lock() defer o.m.Unlock() - if o.done.Load() == 0 { - defer o.done.Store(1) + if !o.done.Load() { + defer o.done.Store(true) f() } } |
