peer: move atomic var increment in msgConsumer goroutine to defer
In this commit we move the atomic var increment that signals the consumer goourtine has exited to the top of the method in a defer statement. This cleans up some duplicate code and also adheres to the pattern of using defers to signal cleaning up any dependent goroutine state on exit.
This commit is contained in:
1 file changed
+1
-2
@@ -738,6 +738,7 @@ func (ms *msgStream) Stop() {
|
||||
func (ms *msgStream) msgConsumer() {
|
||||
defer ms.wg.Done()
|
||||
defer peerLog.Tracef(ms.stopMsg)
|
||||
defer atomic.StoreInt32(&ms.streamShutdown, 1)
|
||||
|
||||
peerLog.Tracef(ms.startMsg)
|
||||
|
||||
@@ -754,7 +755,6 @@ func (ms *msgStream) msgConsumer() {
|
||||
select {
|
||||
case <-ms.quit:
|
||||
ms.msgCond.L.Unlock()
|
||||
atomic.StoreInt32(&ms.streamShutdown, 1)
|
||||
return
|
||||
default:
|
||||
}
|
||||
@@ -778,7 +778,6 @@ func (ms *msgStream) msgConsumer() {
|
||||
select {
|
||||
case ms.producerSema <- struct{}{}:
|
||||
case <-ms.quit:
|
||||
atomic.StoreInt32(&ms.streamShutdown, 1)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user