mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
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:
parent
a7656454aa
commit
e4e4a6ab58
3
peer.go
3
peer.go
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user