Esempio n. 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()
	}
}
Esempio n. 2
0
File: cond.go Progetto: 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")
	}
}
Esempio n. 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
	}
}
Esempio n. 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()
}
Esempio n. 5
0
func CompareAndSwapUintptr(addr *uintptr, old, new uintptr) bool {
	return orig.CompareAndSwapUintptr(addr, old, new)
}
Esempio n. 6
0
func (output *TDOutput) Stop() {
	if atomic.CompareAndSwapUintptr(&output.isShuttingDown, 0, 1) {
		close(output.emitterChan)
	}
}
Esempio n. 7
0
func (input *ForwardInput) Stop() {
	if atomic.CompareAndSwapUintptr(&input.isShuttingDown, uintptr(0), uintptr(1)) {
		input.shutdownChan <- struct{}{}
	}
}
Esempio n. 8
0
func (p *startedChecker) start() {
	if uintptr(*p) == startedCheckerInitialValue {
		atomic.CompareAndSwapUintptr((*uintptr)(p), startedCheckerInitialValue, startedCheckerStartedValue)
	}
}