1 Star 0 Fork 0

Stefan/go-zero

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
spinlock.go 475 Bytes
一键复制 编辑 原始数据 按行查看 历史
kevwan 提交于 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

搜索帮助