mirror of
https://git.zx2c4.com/wireguard-go
synced 2025-10-06 00:57:23 +08:00
device: use defer to simplify peer.NewTimer
This also makes the lifetime of modifyingLock more prominent. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:

committed by
Jason A. Donenfeld

parent
e950ce7bd2
commit
cb94af035e
@@ -29,18 +29,17 @@ func (peer *Peer) NewTimer(expirationFunction func(*Peer)) *Timer {
|
|||||||
timer := &Timer{}
|
timer := &Timer{}
|
||||||
timer.Timer = time.AfterFunc(time.Hour, func() {
|
timer.Timer = time.AfterFunc(time.Hour, func() {
|
||||||
timer.runningLock.Lock()
|
timer.runningLock.Lock()
|
||||||
|
defer timer.runningLock.Unlock()
|
||||||
|
|
||||||
timer.modifyingLock.Lock()
|
timer.modifyingLock.Lock()
|
||||||
if !timer.isPending {
|
if !timer.isPending {
|
||||||
timer.modifyingLock.Unlock()
|
timer.modifyingLock.Unlock()
|
||||||
timer.runningLock.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
timer.isPending = false
|
timer.isPending = false
|
||||||
timer.modifyingLock.Unlock()
|
timer.modifyingLock.Unlock()
|
||||||
|
|
||||||
expirationFunction(peer)
|
expirationFunction(peer)
|
||||||
timer.runningLock.Unlock()
|
|
||||||
})
|
})
|
||||||
timer.Stop()
|
timer.Stop()
|
||||||
return timer
|
return timer
|
||||||
|
Reference in New Issue
Block a user