aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josh@tailscale.com>2020-12-14 15:30:10 -0800
committerJason A. Donenfeld <Jason@zx2c4.com>2020-12-15 18:08:24 +0100
commitcb94af035ee1c4baf7e054a6c7abca0988ffcd59 (patch)
tree1d831f9e8e6262a839533bba032787632c809c84
parentdevice: accept any io.Reader in device.IpcSetOperation (diff)
downloadwireguard-go-cb94af035ee1c4baf7e054a6c7abca0988ffcd59.tar.xz
wireguard-go-cb94af035ee1c4baf7e054a6c7abca0988ffcd59.zip
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>
-rw-r--r--device/timers.go3
1 files changed, 1 insertions, 2 deletions
diff --git a/device/timers.go b/device/timers.go
index 0232eef..48cef94 100644
--- a/device/timers.go
+++ b/device/timers.go
@@ -29,18 +29,17 @@ func (peer *Peer) NewTimer(expirationFunction func(*Peer)) *Timer {
timer := &Timer{}
timer.Timer = time.AfterFunc(time.Hour, func() {
timer.runningLock.Lock()
+ defer timer.runningLock.Unlock()
timer.modifyingLock.Lock()
if !timer.isPending {
timer.modifyingLock.Unlock()
- timer.runningLock.Unlock()
return
}
timer.isPending = false
timer.modifyingLock.Unlock()
expirationFunction(peer)
- timer.runningLock.Unlock()
})
timer.Stop()
return timer