]> Cypherpunks repositories - gostls13.git/commitdiff
sync: name the Map.CompareAndSwap return value
authorPeter Collingbourne <pcc@google.com>
Wed, 20 Mar 2024 02:27:22 +0000 (19:27 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 21 Mar 2024 00:52:58 +0000 (00:52 +0000)
The godoc for sync.Map.CompareAndSwap does not document the meaning
of its return value. Document it by giving it a name.

Change-Id: I50ad9c078a7885f5ce83489d66d138d491c35861
Reviewed-on: https://go-review.googlesource.com/c/go/+/572657
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/sync/map.go

index 7ae97bce1ddb31e7d3f490851ee6b2d6087bf099..504410bc4b8a9dd5138336dc1e59e1ed5bd8fe7a 100644 (file)
@@ -393,7 +393,7 @@ func (m *Map) Swap(key, value any) (previous any, loaded bool) {
 // CompareAndSwap swaps the old and new values for key
 // if the value stored in the map is equal to old.
 // The old value must be of a comparable type.
-func (m *Map) CompareAndSwap(key, old, new any) bool {
+func (m *Map) CompareAndSwap(key, old, new any) (swapped bool) {
        read := m.loadReadOnly()
        if e, ok := read.m[key]; ok {
                return e.tryCompareAndSwap(old, new)
@@ -404,7 +404,7 @@ func (m *Map) CompareAndSwap(key, old, new any) bool {
        m.mu.Lock()
        defer m.mu.Unlock()
        read = m.loadReadOnly()
-       swapped := false
+       swapped = false
        if e, ok := read.m[key]; ok {
                swapped = e.tryCompareAndSwap(old, new)
        } else if e, ok := m.dirty[key]; ok {