github.com/kelleygo/clashcore@v1.0.2/common/once/once_go122.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 atomic.Uint32 13 m sync.Mutex 14 } 15 16 func Done(once *sync.Once) bool { 17 // atomic visit sync.Once.done 18 return (*atomic.Uint32)(unsafe.Pointer(once)).Load() == 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 o.done.Store(0) 26 }