...
1
16
17 package loader
18
19 import (
20 "sync/atomic"
21 "unsafe"
22 _ `unsafe`
23 )
24
25
26
27 var lastmoduledatap *moduledata
28
29 func registerModule(mod *moduledata) {
30 registerModuleLockFree(&lastmoduledatap, mod)
31 }
32
33
34 func moduledataverify1(_ *moduledata)
35
36 func registerModuleLockFree(tail **moduledata, mod *moduledata) {
37 for {
38 oldTail := loadModule(tail)
39 if casModule(tail, oldTail, mod) {
40 storeModule(&oldTail.next, mod)
41 break
42 }
43 }
44 }
45
46 func loadModule(p **moduledata) *moduledata {
47 return (*moduledata)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p))))
48 }
49
50 func storeModule(p **moduledata, value *moduledata) {
51 atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(p)), unsafe.Pointer(value))
52 }
53
54 func casModule(p **moduledata, oldValue *moduledata, newValue *moduledata) bool {
55 return atomic.CompareAndSwapPointer(
56 (*unsafe.Pointer)(unsafe.Pointer(p)),
57 unsafe.Pointer(oldValue),
58 unsafe.Pointer(newValue),
59 )
60 }
61
View as plain text