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:
Olaoluwa Osuntokun 2018-08-24 17:54:26 -07:00
parent a7656454aa
commit e4e4a6ab58
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

View File

@ -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
}
}