Source file
src/runtime/atomic_pointer.go
1
2
3
4
5 package runtime
6
7 import (
8 "runtime/internal/atomic"
9 "unsafe"
10 )
11
12
13
14
15
16
17
18
19
20
21 func atomicwb(ptr *unsafe.Pointer, new unsafe.Pointer) {
22 slot := (*uintptr)(unsafe.Pointer(ptr))
23 if !getg().m.p.ptr().wbBuf.putFast(*slot, uintptr(new)) {
24 wbBufFlush(slot, uintptr(new))
25 }
26 }
27
28
29
30
31 func atomicstorep(ptr unsafe.Pointer, new unsafe.Pointer) {
32 if writeBarrier.enabled {
33 atomicwb((*unsafe.Pointer)(ptr), new)
34 }
35 atomic.StorepNoWB(noescape(ptr), new)
36 }
37
38
39
40
41
42
43 func sync_atomic_StoreUintptr(ptr *uintptr, new uintptr)
44
45
46
47 func sync_atomic_StorePointer(ptr *unsafe.Pointer, new unsafe.Pointer) {
48 if writeBarrier.enabled {
49 atomicwb(ptr, new)
50 }
51 sync_atomic_StoreUintptr((*uintptr)(unsafe.Pointer(ptr)), uintptr(new))
52 }
53
54
55 func sync_atomic_SwapUintptr(ptr *uintptr, new uintptr) uintptr
56
57
58
59 func sync_atomic_SwapPointer(ptr *unsafe.Pointer, new unsafe.Pointer) unsafe.Pointer {
60 if writeBarrier.enabled {
61 atomicwb(ptr, new)
62 }
63 old := unsafe.Pointer(sync_atomic_SwapUintptr((*uintptr)(noescape(unsafe.Pointer(ptr))), uintptr(new)))
64 return old
65 }
66
67
68 func sync_atomic_CompareAndSwapUintptr(ptr *uintptr, old, new uintptr) bool
69
70
71
72 func sync_atomic_CompareAndSwapPointer(ptr *unsafe.Pointer, old, new unsafe.Pointer) bool {
73 if writeBarrier.enabled {
74 atomicwb(ptr, new)
75 }
76 return sync_atomic_CompareAndSwapUintptr((*uintptr)(noescape(unsafe.Pointer(ptr))), uintptr(old), uintptr(new))
77 }
78
View as plain text