From c9e4a859ae8cdd7046a467afe8b50c5364c2cfc7 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 10 Dec 2020 11:25:08 -0800 Subject: device: remove starting waitgroups In each case, the starting waitgroup did nothing but ensure that the goroutine has launched. Nothing downstream depends on the order in which goroutines launch, and if the Go runtime scheduler is so broken that goroutines don't get launched reasonably promptly, we have much deeper problems. Given all that, simplify the code. Passed a race-enabled stress test 25,000 times without failure. Signed-off-by: Josh Bleecher Snyder --- device/peer.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'device/peer.go') diff --git a/device/peer.go b/device/peer.go index 78204bb..02e145c 100644 --- a/device/peer.go +++ b/device/peer.go @@ -66,8 +66,7 @@ type Peer struct { } routines struct { - sync.Mutex // held when stopping / starting routines - starting sync.WaitGroup // routines pending start + sync.Mutex // held when stopping routines stopping sync.WaitGroup // routines pending stop stop chan struct{} // size 0, stop all go routines in peer } @@ -189,10 +188,8 @@ func (peer *Peer) Start() { // reset routine state - peer.routines.starting.Wait() peer.routines.stopping.Wait() peer.routines.stop = make(chan struct{}) - peer.routines.starting.Add(PeerRoutineNumber) peer.routines.stopping.Add(PeerRoutineNumber) // prepare queues @@ -213,7 +210,6 @@ func (peer *Peer) Start() { go peer.RoutineSequentialSender() go peer.RoutineSequentialReceiver() - peer.routines.starting.Wait() peer.isRunning.Set(true) } @@ -270,8 +266,6 @@ func (peer *Peer) Stop() { return } - peer.routines.starting.Wait() - peer.routines.Lock() defer peer.routines.Unlock() -- cgit v1.2.3