Change-Id: I95c941f83f74d57dfdd2d6803c9059691fb649b8
Reviewed-on: https://go-review.googlesource.com/c/go/+/422176
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: hopehook <hopehook@qq.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
}
type cacheEntry struct {
- done uint32
+ done atomic.Bool
mu sync.Mutex
result any
}
entryIface, _ = c.m.LoadOrStore(key, new(cacheEntry))
}
e := entryIface.(*cacheEntry)
- if atomic.LoadUint32(&e.done) == 0 {
+ if !e.done.Load() {
e.mu.Lock()
- if atomic.LoadUint32(&e.done) == 0 {
+ if !e.done.Load() {
e.result = f()
- atomic.StoreUint32(&e.done, 1)
+ e.done.Store(true)
}
e.mu.Unlock()
}
return nil
}
e := entryIface.(*cacheEntry)
- if atomic.LoadUint32(&e.done) == 0 {
+ if !e.done.Load() {
return nil
}
return e.result