github.com/kelleygo/clashcore@v1.0.2/common/once/once_go120.go (about) 1 //go:build !go1.22 2 3 package once 4 5 import ( 6 "sync" 7 "sync/atomic" 8 "unsafe" 9 ) 10 11 type Once struct { 12 done uint32 13 m sync.Mutex 14 } 15 16 func Done(once *sync.Once) bool { 17 // atomic visit sync.Once.done 18 return atomic.LoadUint32((*uint32)(unsafe.Pointer(once))) == 1 19 } 20 21 func Reset(once *sync.Once) { 22 o := (*Once)(unsafe.Pointer(once)) 23 o.m.Lock() 24 defer o.m.Unlock() 25 atomic.StoreUint32(&o.done, 0) 26 }