From 97259c5d6b5928b4519a227b2e5a540259c49bbd Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Fri, 27 Feb 2026 23:38:49 -0500 Subject: sync: replace linkname with import The sync package uses linkname to access internal/runtime/atomic package's LoadAcquintptr and StoreReluintptr functions. It was not able to import the package when the package was runtime/internal/atomic. Now that it moves to internal/runtime, the sync package can just import it and call the functions normally. Change-Id: Ic7399e33d0e965fdcdf505be67a7f90e0260ddee Reviewed-on: https://go-review.googlesource.com/c/go/+/750160 LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Pratt --- src/sync/pool.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'src/sync') diff --git a/src/sync/pool.go b/src/sync/pool.go index f9a8405b79..4008011341 100644 --- a/src/sync/pool.go +++ b/src/sync/pool.go @@ -6,6 +6,7 @@ package sync import ( "internal/race" + rtatomic "internal/runtime/atomic" "runtime" "sync/atomic" "unsafe" @@ -159,8 +160,8 @@ func (p *Pool) Get() any { func (p *Pool) getSlow(pid int) any { // See the comment in pin regarding ordering of the loads. - size := runtime_LoadAcquintptr(&p.localSize) // load-acquire - locals := p.local // load-consume + size := rtatomic.LoadAcquintptr(&p.localSize) // load-acquire + locals := p.local // load-consume // Try to steal one element from other procs. for i := 0; i < int(size); i++ { l := indexLocal(locals, (pid+i+1)%int(size)) @@ -212,8 +213,8 @@ func (p *Pool) pin() (*poolLocal, int) { // Since we've disabled preemption, GC cannot happen in between. // Thus here we must observe local at least as large localSize. // We can observe a newer/larger local, it is fine (we must observe its zero-initialized-ness). - s := runtime_LoadAcquintptr(&p.localSize) // load-acquire - l := p.local // load-consume + s := rtatomic.LoadAcquintptr(&p.localSize) // load-acquire + l := p.local // load-consume if uintptr(pid) < s { return indexLocal(l, pid), pid } @@ -240,7 +241,7 @@ func (p *Pool) pinSlow() (*poolLocal, int) { size := runtime.GOMAXPROCS(0) local := make([]poolLocal, size) atomic.StorePointer(&p.local, unsafe.Pointer(&local[0])) // store-release - runtime_StoreReluintptr(&p.localSize, uintptr(size)) // store-release + rtatomic.StoreReluintptr(&p.localSize, uintptr(size)) // store-release return &local[pid], pid } @@ -306,13 +307,3 @@ func indexLocal(l unsafe.Pointer, i int) *poolLocal { func runtime_registerPoolCleanup(cleanup func()) func runtime_procPin() int func runtime_procUnpin() - -// The below are implemented in internal/runtime/atomic and the -// compiler also knows to intrinsify the symbol we linkname into this -// package. - -//go:linkname runtime_LoadAcquintptr internal/runtime/atomic.LoadAcquintptr -func runtime_LoadAcquintptr(ptr *uintptr) uintptr - -//go:linkname runtime_StoreReluintptr internal/runtime/atomic.StoreReluintptr -func runtime_StoreReluintptr(ptr *uintptr, val uintptr) -- cgit v1.3-6-g1900