fix golint issues in core/syncx (#526)

This commit is contained in:
Kevin Wan
2021-02-28 16:16:22 +08:00
committed by GitHub
parent f02711a9cb
commit 490241d639
18 changed files with 73 additions and 2 deletions

View File

@@ -5,20 +5,24 @@ import (
"sync/atomic"
)
// A SpinLock is used as a lock a fast execution.
type SpinLock struct {
lock uint32
}
// Lock locks the SpinLock.
func (sl *SpinLock) Lock() {
for !sl.TryLock() {
runtime.Gosched()
}
}
// TryLock tries to lock the SpinLock.
func (sl *SpinLock) TryLock() bool {
return atomic.CompareAndSwapUint32(&sl.lock, 0, 1)
}
// Unlock unlocks the SpinLock.
func (sl *SpinLock) Unlock() {
atomic.StoreUint32(&sl.lock, 0)
}