Source file
src/runtime/atomic_pointer.go
1
2
3
4
5 package runtime
6
7 import (
8 "internal/goexperiment"
9 "internal/runtime/atomic"
10 "unsafe"
11 )
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 func atomicwb(ptr *unsafe.Pointer, new unsafe.Pointer) {
33 slot := (*uintptr)(unsafe.Pointer(ptr))
34 buf := getg().m.p.ptr().wbBuf.get2()
35 buf[0] = *slot
36 buf[1] = uintptr(new)
37 }
38
39
40
41
42 func atomicstorep(ptr unsafe.Pointer, new unsafe.Pointer) {
43 if writeBarrier.enabled {
44 atomicwb((*unsafe.Pointer)(ptr), new)
45 }
46 if goexperiment.CgoCheck2 {
47 cgoCheckPtrWrite((*unsafe.Pointer)(ptr), new)
48 }
49 atomic.StorepNoWB(noescape(ptr), new)
50 }
51
52
53
54
55
56
57 func atomic_storePointer(ptr *unsafe.Pointer, new unsafe.Pointer) {
58 atomicstorep(unsafe.Pointer(ptr), new)
59 }
60
61
62
63
64
65
66 func atomic_casPointer(ptr *unsafe.Pointer, old, new unsafe.Pointer) bool {
67 if writeBarrier.enabled {
68 atomicwb(ptr, new)
69 }
70 if goexperiment.CgoCheck2 {
71 cgoCheckPtrWrite(ptr, new)
72 }
73 return atomic.Casp1(ptr, old, new)
74 }
75
76
77
78
79
80
81 func sync_atomic_StoreUintptr(ptr *uintptr, new uintptr)
82
83
84
85 func sync_atomic_StorePointer(ptr *unsafe.Pointer, new unsafe.Pointer) {
86 if writeBarrier.enabled {
87 atomicwb(ptr, new)
88 }
89 if goexperiment.CgoCheck2 {
90 cgoCheckPtrWrite(ptr, new)
91 }
92 sync_atomic_StoreUintptr((*uintptr)(unsafe.Pointer(ptr)), uintptr(new))
93 }
94
95
96 func sync_atomic_SwapUintptr(ptr *uintptr, new uintptr) uintptr
97
98
99
100 func sync_atomic_SwapPointer(ptr *unsafe.Pointer, new unsafe.Pointer) unsafe.Pointer {
101 if writeBarrier.enabled {
102 atomicwb(ptr, new)
103 }
104 if goexperiment.CgoCheck2 {
105 cgoCheckPtrWrite(ptr, new)
106 }
107 old := unsafe.Pointer(sync_atomic_SwapUintptr((*uintptr)(noescape(unsafe.Pointer(ptr))), uintptr(new)))
108 return old
109 }
110
111
112 func sync_atomic_CompareAndSwapUintptr(ptr *uintptr, old, new uintptr) bool
113
114
115
116 func sync_atomic_CompareAndSwapPointer(ptr *unsafe.Pointer, old, new unsafe.Pointer) bool {
117 if writeBarrier.enabled {
118 atomicwb(ptr, new)
119 }
120 if goexperiment.CgoCheck2 {
121 cgoCheckPtrWrite(ptr, new)
122 }
123 return sync_atomic_CompareAndSwapUintptr((*uintptr)(noescape(unsafe.Pointer(ptr))), uintptr(old), uintptr(new))
124 }
125
View as plain text