github.com/hamersaw/flytestdlib@v0.2.28/atomic/non_blocking_lock.go (about) 1 package atomic 2 3 // Lock that provides TryLock method instead of blocking lock 4 type NonBlockingLock interface { 5 TryLock() bool 6 Release() 7 } 8 9 func NewNonBlockingLock() NonBlockingLock { 10 return &nonBlockingLock{lock: NewBool(false)} 11 } 12 13 type nonBlockingLock struct { 14 lock Bool 15 } 16 17 func (n *nonBlockingLock) TryLock() bool { 18 return n.lock.CompareAndSwap(false, true) 19 } 20 21 func (n *nonBlockingLock) Release() { 22 n.lock.Store(false) 23 }