1
0
mirror of https://github.com/golang/go synced 2024-11-26 14:08:37 -07:00

runtime/cgo: use atomic.Uintptr instead of atomic.AddUintptr.

cgo.NewHandle atomically increments a global uintptr index using
atomic.AddUintptr. Use atomic.Uintptr instead, which is
cleaner and clearer.

Change-Id: I845b3e4cb8c461e787a9b9bb2a9ceaaef1d21d8e
Reviewed-on: https://go-review.googlesource.com/c/go/+/490775
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
qmuntal 2023-04-30 11:38:00 +02:00 committed by Gopher Robot
parent d1f0552892
commit 5901ab80b9

View File

@ -106,7 +106,7 @@ type Handle uintptr
// The intended use is to pass the returned handle to C code, which
// passes it back to Go, which calls Value.
func NewHandle(v any) Handle {
h := atomic.AddUintptr(&handleIdx, 1)
h := handleIdx.Add(1)
if h == 0 {
panic("runtime/cgo: ran out of handle space")
}
@ -140,5 +140,5 @@ func (h Handle) Delete() {
var (
handles = sync.Map{} // map[Handle]interface{}
handleIdx uintptr // atomic
handleIdx atomic.Uintptr
)