]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/par: change cacheEntry.done type to atomic.Bool
authorLudi Rehak <ludi317@gmail.com>
Tue, 9 Aug 2022 01:55:56 +0000 (18:55 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 26 Aug 2022 17:41:34 +0000 (17:41 +0000)
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>

src/cmd/go/internal/par/work.go

index 496c41b1509281bcea9b1ba5abfda1effe605e4f..7626251087bd50bdf0cf26c3a9af0fa7d3bc5da1 100644 (file)
@@ -108,7 +108,7 @@ type Cache struct {
 }
 
 type cacheEntry struct {
-       done   uint32
+       done   atomic.Bool
        mu     sync.Mutex
        result any
 }
@@ -122,11 +122,11 @@ func (c *Cache) Do(key any, f func() any) 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()
        }
@@ -142,7 +142,7 @@ func (c *Cache) Get(key any) any {
                return nil
        }
        e := entryIface.(*cacheEntry)
-       if atomic.LoadUint32(&e.done) == 0 {
+       if !e.done.Load() {
                return nil
        }
        return e.result