From 5901ab80b9c9ac2daa7c30f0c0ede3b7adfc7007 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Sun, 30 Apr 2023 11:38:00 +0200 Subject: [PATCH] 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 TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills Auto-Submit: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor --- src/runtime/cgo/handle.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/cgo/handle.go b/src/runtime/cgo/handle.go index d711900d79..061dfb0e2e 100644 --- a/src/runtime/cgo/handle.go +++ b/src/runtime/cgo/handle.go @@ -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 ) -- 2.50.0