func (m *Mutex) lock() { state := atomic.LoadUintptr(&m.state) if state == 0 { state = uintptr(noos.AssignEventFlag()) if !atomic.CompareAndSwapUintptr(&m.state, 0, state) { state = m.state } } unlocked, locked := state&^1, state|1 for { if atomic.CompareAndSwapUintptr(&m.state, unlocked, locked) { return } noos.Event(unlocked).Wait() } }
func (c *copyChecker) check() { if uintptr(*c) != uintptr(unsafe.Pointer(c)) && !atomic.CompareAndSwapUintptr((*uintptr)(c), 0, uintptr(unsafe.Pointer(c))) && uintptr(*c) != uintptr(unsafe.Pointer(c)) { panic("sync.Cond is copied") } }
func (c *copyChecker) check() { if uintptr(*c) != uintptr(unsafe.Pointer(c)) && !atomic.CompareAndSwapUintptr((*uintptr)(c), 0, uintptr(unsafe.Pointer(c))) && uintptr(*c) != uintptr(unsafe.Pointer(c)) { // 如果c不指向自身了,或者c本身为空(初始化的情况,这时给c赋值), panic("sync.Cond is copied") // 如果初始化失败,或者不指向自身了,panic } }
func (daemon *tdOutputSpoolerDaemon) cleanup() { func() { daemon.spoolersMtx.Lock() defer daemon.spoolersMtx.Unlock() for _, spooler := range daemon.spoolers { if atomic.CompareAndSwapUintptr(&spooler.isShuttingDown, 0, 1) { spooler.shutdownChan <- struct{}{} } } }() daemon.wg.Wait() if daemon.endNotify != nil { daemon.endNotify(daemon) } daemon.output.wg.Done() }
func CompareAndSwapUintptr(addr *uintptr, old, new uintptr) bool { return orig.CompareAndSwapUintptr(addr, old, new) }
func (output *TDOutput) Stop() { if atomic.CompareAndSwapUintptr(&output.isShuttingDown, 0, 1) { close(output.emitterChan) } }
func (input *ForwardInput) Stop() { if atomic.CompareAndSwapUintptr(&input.isShuttingDown, uintptr(0), uintptr(1)) { input.shutdownChan <- struct{}{} } }
func (p *startedChecker) start() { if uintptr(*p) == startedCheckerInitialValue { atomic.CompareAndSwapUintptr((*uintptr)(p), startedCheckerInitialValue, startedCheckerStartedValue) } }