代码拉取完成,页面将自动刷新
// Package gmlock implements a concurrent-safe memory-based locker.
package gmlock
var (
// Default locker.
locker = New()
)
// Lock locks the <key> with writing lock.
// If there's a write/reading lock the <key>,
// it will blocks until the lock is released.
func Lock(key string) {
locker.Lock(key)
}
// TryLock tries locking the <key> with writing lock,
// it returns true if success, or if there's a write/reading lock the <key>,
// it returns false.
func TryLock(key string) bool {
return locker.TryLock(key)
}
// Unlock unlocks the writing lock of the <key>.
func Unlock(key string) {
locker.Unlock(key)
}
// RLock locks the <key> with reading lock.
// If there's a writing lock on <key>,
// it will blocks until the writing lock is released.
func RLock(key string) {
locker.RLock(key)
}
// TryRLock tries locking the <key> with reading lock.
// It returns true if success, or if there's a writing lock on <key>, it returns false.
func TryRLock(key string) bool {
return locker.TryRLock(key)
}
// RUnlock unlocks the reading lock of the <key>.
func RUnlock(key string) {
locker.RUnlock(key)
}
// LockFunc locks the <key> with writing lock and callback function <f>.
// If there's a write/reading lock the <key>,
// it will blocks until the lock is released.
//
// It releases the lock after <f> is executed.
func LockFunc(key string, f func()) {
locker.LockFunc(key, f)
}
// RLockFunc locks the <key> with reading lock and callback function <f>.
// If there's a writing lock the <key>,
// it will blocks until the lock is released.
//
// It releases the lock after <f> is executed.
func RLockFunc(key string, f func()) {
locker.RLockFunc(key, f)
}
// TryLockFunc locks the <key> with writing lock and callback function <f>.
// It returns true if success, or else if there's a write/reading lock the <key>, it return false.
//
// It releases the lock after <f> is executed.
func TryLockFunc(key string, f func()) bool {
return locker.TryLockFunc(key, f)
}
// TryRLockFunc locks the <key> with reading lock and callback function <f>.
// It returns true if success, or else if there's a writing lock the <key>, it returns false.
//
// It releases the lock after <f> is executed.
func TryRLockFunc(key string, f func()) bool {
return locker.TryRLockFunc(key, f)
}
// Remove removes mutex with given <key>.
func Remove(key string) {
locker.Remove(key)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。