mirror of
https://github.com/golang/go
synced 2024-11-25 10:07:56 -07:00
sync: use atomic.Store in Once.Do
No perf/semantic changes, merely improves code health. There were several questions as to why Once.Do uses atomic.CompareAndSwap to do a store. R=golang-dev, r CC=golang-dev https://golang.org/cl/6208057
This commit is contained in:
parent
58bcec62c0
commit
8c4c6c413f
@ -38,6 +38,6 @@ func (o *Once) Do(f func()) {
|
||||
defer o.m.Unlock()
|
||||
if o.done == 0 {
|
||||
f()
|
||||
atomic.CompareAndSwapUint32(&o.done, 0, 1)
|
||||
atomic.StoreUint32(&o.done, 1)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user