summaryrefslogtreecommitdiffhomepage
path: root/peer.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-05-16 22:20:15 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-05-16 22:20:15 +0200
commit846d721dfd0cde953f2e9304d6ef50110de050eb (patch)
tree8de15914ab39d0aad1b50d03530b82fece54c740 /peer.go
parent23eca94508d7cef0c1adbbc37c81050899ca1d60 (diff)
Finer-grained start-stop synchronization
Diffstat (limited to 'peer.go')
-rw-r--r--peer.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/peer.go b/peer.go
index 4bc1ada..3808ad6 100644
--- a/peer.go
+++ b/peer.go
@@ -231,20 +231,21 @@ func (peer *Peer) Stop() {
// prevent simultaneous start/stop operations
- peer.routines.mutex.Lock()
- defer peer.routines.mutex.Unlock()
-
if !peer.isRunning.Swap(false) {
return
}
+ peer.routines.starting.Wait()
+
+ peer.routines.mutex.Lock()
+ defer peer.routines.mutex.Unlock()
+
peer.device.log.Debug.Println(peer, ": Stopping...")
peer.timersStop()
// stop & wait for ongoing peer routines
- peer.routines.starting.Wait()
close(peer.routines.stop)
peer.routines.stopping.Wait()