Skip to content

Commit

Permalink
Optimize unset lock data when event loop waits for clear
Browse files Browse the repository at this point in the history
  • Loading branch information
snower committed May 18, 2024
1 parent 0f86946 commit 3cf2c9c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions client/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (self *Event) Wait(timeout uint32) (*protocol.LockResultCommand, error) {
func (self *Event) WaitAndTimeoutRetryClear(timeout uint32) (*protocol.LockResultCommand, error) {
if self.setedMode == EVENT_MODE_DEFAULT_SET {
self.waitLock = &Lock{self.db, self.db.GenLockId(), self.eventKey, timeout, 0, 0, 0}
result, err := self.waitLock.Lock()
result, err := self.waitLock.LockWithData(protocol.NewLockCommandDataUnsetData())
if err == nil {
return result, nil
}
Expand All @@ -217,7 +217,7 @@ func (self *Event) WaitAndTimeoutRetryClear(timeout uint32) (*protocol.LockResul
}
self.glock.Unlock()

rresult, rerr := self.eventLock.LockUpdate()
rresult, rerr := self.eventLock.LockUpdateWithData(protocol.NewLockCommandDataUnsetData())
if rerr == nil {
if rresult.Result == protocol.RESULT_SUCCED {
_, _ = self.eventLock.Unlock()
Expand All @@ -232,7 +232,7 @@ func (self *Event) WaitAndTimeoutRetryClear(timeout uint32) (*protocol.LockResul
}

self.waitLock = &Lock{self.db, self.db.GenLockId(), self.eventKey, timeout | 0x02000000, 0, 1, 0}
result, err := self.waitLock.Lock()
result, err := self.waitLock.LockWithData(protocol.NewLockCommandDataUnsetData())
if err == nil {
self.glock.Lock()
if self.eventLock == nil {
Expand Down
4 changes: 2 additions & 2 deletions client/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (self *GroupEvent) WaitAndTimeoutRetryClear(timeout uint32) (*protocol.Lock
byte(self.clientId >> 32), byte(self.clientId >> 40), byte(self.clientId >> 48), byte(self.clientId >> 56)}
timeout = timeout | uint32(protocol.TIMEOUT_FLAG_LESS_LOCK_VERSION_IS_LOCK_SUCCED)<<16
self.waitLock = &Lock{self.db, lockId, self.groupKey, timeout, 0, 0, 0}
lockResultCommand, err := self.waitLock.doLock(0, self.waitLock.lockId, self.waitLock.timeout, self.waitLock.expried, self.waitLock.count, self.waitLock.rcount, nil)
lockResultCommand, err := self.waitLock.doLock(0, self.waitLock.lockId, self.waitLock.timeout, self.waitLock.expried, self.waitLock.count, self.waitLock.rcount, protocol.NewLockCommandDataUnsetData())
if err != nil {
return lockResultCommand, &LockError{0x80, lockResultCommand, err}
}
Expand All @@ -193,7 +193,7 @@ func (self *GroupEvent) WaitAndTimeoutRetryClear(timeout uint32) (*protocol.Lock
self.eventLock = &Lock{self.db, lockId, self.groupKey, timeout, self.expried, 0, 0}
self.glock.Unlock()

rresult, rerr := self.eventLock.LockUpdate()
rresult, rerr := self.eventLock.LockUpdateWithData(protocol.NewLockCommandDataUnsetData())
if rerr == nil {
if rresult.Result == protocol.RESULT_SUCCED {
_, _ = self.eventLock.Unlock()
Expand Down

0 comments on commit 3cf2c9c

Please sign in to comment.