1 Star 0 Fork 0

Cloudy/guac

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
counted_lock.go 551 Bytes
一键复制 编辑 原始数据 按行查看 历史
jake 提交于 2019-09-17 12:05 . use Go naming conventions
package guac
import (
"sync"
"sync/atomic"
)
// CountedLock counts how many goroutines are waiting on the lock
type CountedLock struct {
core sync.Mutex
numLocks int32
}
// Lock locks the mutex
func (r *CountedLock) Lock() {
atomic.AddInt32(&r.numLocks, 1)
r.core.Lock()
}
// Unlock unlocks the mutex
func (r *CountedLock) Unlock() {
atomic.AddInt32(&r.numLocks, -1)
r.core.Unlock()
}
// HasQueued returns true if a goroutine is waiting on the lock
func (r *CountedLock) HasQueued() bool {
return atomic.LoadInt32(&r.numLocks) > 1
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/itcloudy/guac.git
git@gitee.com:itcloudy/guac.git
itcloudy
guac
guac
master

搜索帮助