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