1 Star 0 Fork 0

Stefan/go-zero

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
spinlock.go 475 Bytes
Copy Edit Raw Blame History
kevwan authored 2021-02-28 16:16 +08:00 . fix golint issues in core/syncx (#526)
package syncx
import (
"runtime"
"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)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/stefan886/go-zero.git
git@gitee.com:stefan886/go-zero.git
stefan886
go-zero
go-zero
45236c288c2b

Search