示例#1
0
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()
	}
}
示例#2
0
文件: cond.go 项目: sreis/go
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")
	}
}
示例#3
0
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
	}
}
示例#4
0
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()
}
示例#5
0
func CompareAndSwapUintptr(addr *uintptr, old, new uintptr) bool {
	return orig.CompareAndSwapUintptr(addr, old, new)
}
示例#6
0
func (output *TDOutput) Stop() {
	if atomic.CompareAndSwapUintptr(&output.isShuttingDown, 0, 1) {
		close(output.emitterChan)
	}
}
示例#7
0
func (input *ForwardInput) Stop() {
	if atomic.CompareAndSwapUintptr(&input.isShuttingDown, uintptr(0), uintptr(1)) {
		input.shutdownChan <- struct{}{}
	}
}
示例#8
0
func (p *startedChecker) start() {
	if uintptr(*p) == startedCheckerInitialValue {
		atomic.CompareAndSwapUintptr((*uintptr)(p), startedCheckerInitialValue, startedCheckerStartedValue)
	}
}