Skip to content

Commit d96cb9b

Browse files
all: move procPin and procUnpin to internal/runtime
For #65355 Change-Id: I42c04ade295d2900f55596ad2f223c9c93dd740f
1 parent 7f76c00 commit d96cb9b

File tree

5 files changed

+24
-59
lines changed

5 files changed

+24
-59
lines changed

src/go/build/deps_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ var depsRules = `
5050
unicode/utf8, unicode/utf16, unicode,
5151
unsafe;
5252
53+
unsafe < internal/runtime;
54+
5355
# These packages depend only on internal/goarch and unsafe.
5456
internal/goarch, unsafe
5557
< internal/abi, internal/chacha8rand;
@@ -64,7 +66,8 @@ var depsRules = `
6466
internal/goarch,
6567
internal/godebugs,
6668
internal/goexperiment,
67-
internal/goos
69+
internal/goos,
70+
internal/runtime
6871
< internal/bytealg
6972
< internal/itoa
7073
< internal/unsafeheader

src/runtime/proc.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6921,42 +6921,6 @@ func procUnpin() {
69216921
gp.m.locks--
69226922
}
69236923

6924-
//go:linkname sync_runtime_procPin sync.runtime_procPin
6925-
//go:nosplit
6926-
func sync_runtime_procPin() int {
6927-
return procPin()
6928-
}
6929-
6930-
//go:linkname sync_runtime_procUnpin sync.runtime_procUnpin
6931-
//go:nosplit
6932-
func sync_runtime_procUnpin() {
6933-
procUnpin()
6934-
}
6935-
6936-
//go:linkname sync_atomic_runtime_procPin sync/atomic.runtime_procPin
6937-
//go:nosplit
6938-
func sync_atomic_runtime_procPin() int {
6939-
return procPin()
6940-
}
6941-
6942-
//go:linkname sync_atomic_runtime_procUnpin sync/atomic.runtime_procUnpin
6943-
//go:nosplit
6944-
func sync_atomic_runtime_procUnpin() {
6945-
procUnpin()
6946-
}
6947-
6948-
//go:linkname internal_weak_runtime_procPin internal/weak.runtime_procPin
6949-
//go:nosplit
6950-
func internal_weak_runtime_procPin() int {
6951-
return procPin()
6952-
}
6953-
6954-
//go:linkname internal_weak_runtime_procUnpin internal/weak.runtime_procUnpin
6955-
//go:nosplit
6956-
func internal_weak_runtime_procUnpin() {
6957-
procUnpin()
6958-
}
6959-
69606924
// Active spinning for sync.Mutex.
69616925
//
69626926
//go:linkname sync_runtime_canSpin sync.runtime_canSpin

src/sync/atomic/value.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package atomic
66

77
import (
8+
rt "internal/runtime"
89
"unsafe"
910
)
1011

@@ -56,15 +57,15 @@ func (v *Value) Store(val any) {
5657
// Attempt to start first store.
5758
// Disable preemption so that other goroutines can use
5859
// active spin wait to wait for completion.
59-
runtime_procPin()
60+
rt.ProcPin()
6061
if !CompareAndSwapPointer(&vp.typ, nil, unsafe.Pointer(&firstStoreInProgress)) {
61-
runtime_procUnpin()
62+
rt.ProcUnpin()
6263
continue
6364
}
6465
// Complete first store.
6566
StorePointer(&vp.data, vlp.data)
6667
StorePointer(&vp.typ, vlp.typ)
67-
runtime_procUnpin()
68+
rt.ProcUnpin()
6869
return
6970
}
7071
if typ == unsafe.Pointer(&firstStoreInProgress) {
@@ -100,15 +101,15 @@ func (v *Value) Swap(new any) (old any) {
100101
// Disable preemption so that other goroutines can use
101102
// active spin wait to wait for completion; and so that
102103
// GC does not see the fake type accidentally.
103-
runtime_procPin()
104+
rt.ProcPin()
104105
if !CompareAndSwapPointer(&vp.typ, nil, unsafe.Pointer(&firstStoreInProgress)) {
105-
runtime_procUnpin()
106+
rt.ProcUnpin()
106107
continue
107108
}
108109
// Complete first store.
109110
StorePointer(&vp.data, np.data)
110111
StorePointer(&vp.typ, np.typ)
111-
runtime_procUnpin()
112+
rt.ProcUnpin()
112113
return nil
113114
}
114115
if typ == unsafe.Pointer(&firstStoreInProgress) {
@@ -152,15 +153,15 @@ func (v *Value) CompareAndSwap(old, new any) (swapped bool) {
152153
// Disable preemption so that other goroutines can use
153154
// active spin wait to wait for completion; and so that
154155
// GC does not see the fake type accidentally.
155-
runtime_procPin()
156+
rt.ProcPin()
156157
if !CompareAndSwapPointer(&vp.typ, nil, unsafe.Pointer(&firstStoreInProgress)) {
157-
runtime_procUnpin()
158+
rt.ProcUnpin()
158159
continue
159160
}
160161
// Complete first store.
161162
StorePointer(&vp.data, np.data)
162163
StorePointer(&vp.typ, np.typ)
163-
runtime_procUnpin()
164+
rt.ProcUnpin()
164165
return true
165166
}
166167
if typ == unsafe.Pointer(&firstStoreInProgress) {
@@ -188,7 +189,3 @@ func (v *Value) CompareAndSwap(old, new any) (swapped bool) {
188189
return CompareAndSwapPointer(&vp.data, data, np.data)
189190
}
190191
}
191-
192-
// Disable/enable preemption, implemented in runtime.
193-
func runtime_procPin() int
194-
func runtime_procUnpin()

src/sync/export_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
package sync
66

7+
import "internal/runtime"
8+
79
// Export for testing.
810
var Runtime_Semacquire = runtime_Semacquire
911
var Runtime_Semrelease = runtime_Semrelease
10-
var Runtime_procPin = runtime_procPin
11-
var Runtime_procUnpin = runtime_procUnpin
12+
var Runtime_procPin = runtime.ProcPin
13+
var Runtime_procUnpin = runtime.ProcUnpin
1214

1315
// poolDequeue testing.
1416
type PoolDequeue interface {

src/sync/pool.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package sync
66

77
import (
88
"internal/race"
9+
rt "internal/runtime"
910
"runtime"
1011
"sync/atomic"
1112
"unsafe"
@@ -112,7 +113,7 @@ func (p *Pool) Put(x any) {
112113
} else {
113114
l.shared.pushHead(x)
114115
}
115-
runtime_procUnpin()
116+
rt.ProcUnpin()
116117
if race.Enabled {
117118
race.Enable()
118119
}
@@ -142,7 +143,7 @@ func (p *Pool) Get() any {
142143
x = p.getSlow(pid)
143144
}
144145
}
145-
runtime_procUnpin()
146+
rt.ProcUnpin()
146147
if race.Enabled {
147148
race.Enable()
148149
if x != nil {
@@ -205,7 +206,7 @@ func (p *Pool) pin() (*poolLocal, int) {
205206
panic("nil Pool")
206207
}
207208

208-
pid := runtime_procPin()
209+
pid := rt.ProcPin()
209210
// In pinSlow we store to local and then to localSize, here we load in opposite order.
210211
// Since we've disabled preemption, GC cannot happen in between.
211212
// Thus here we must observe local at least as large localSize.
@@ -221,10 +222,10 @@ func (p *Pool) pin() (*poolLocal, int) {
221222
func (p *Pool) pinSlow() (*poolLocal, int) {
222223
// Retry under the mutex.
223224
// Can not lock the mutex while pinned.
224-
runtime_procUnpin()
225+
rt.ProcUnpin()
225226
allPoolsMu.Lock()
226227
defer allPoolsMu.Unlock()
227-
pid := runtime_procPin()
228+
pid := rt.ProcPin()
228229
// poolCleanup won't be called while we are pinned.
229230
s := p.localSize
230231
l := p.local
@@ -292,8 +293,6 @@ func indexLocal(l unsafe.Pointer, i int) *poolLocal {
292293

293294
// Implemented in runtime.
294295
func runtime_registerPoolCleanup(cleanup func())
295-
func runtime_procPin() int
296-
func runtime_procUnpin()
297296

298297
// The below are implemented in internal/runtime/atomic and the
299298
// compiler also knows to intrinsify the symbol we linkname into this

0 commit comments

Comments
 (0)