新增:trylock 尝试获取锁,并立即返回加锁结果
This commit is contained in:
@@ -95,9 +95,10 @@ type ZConn struct { //ZConn
|
||||
}
|
||||
|
||||
type Lock struct {
|
||||
key string
|
||||
uuid string
|
||||
duration int
|
||||
cmd string // lock|trylock|unlock
|
||||
key string // lock key
|
||||
uuid string // apply for unique identification
|
||||
duration int // lock duration (seconds)
|
||||
timer *time.Timer
|
||||
start int64
|
||||
//stop time.Time
|
||||
@@ -432,7 +433,12 @@ func (s *ZBus) _lock(lock *Lock) {
|
||||
}
|
||||
}()
|
||||
} else {
|
||||
s.locks[lock.key] = append(locks, lock)
|
||||
switch lock.cmd {
|
||||
case "trylock": // send trylock fail message
|
||||
s.broadcast("trylock", lock.uuid)
|
||||
case "lock":
|
||||
s.locks[lock.key] = append(locks, lock)
|
||||
}
|
||||
}
|
||||
}
|
||||
func (s *ZBus) _unlock(l Lock) {
|
||||
|
||||
Reference in New Issue
Block a user