From 83cffc5d27479a844133f6b0f6f00d39895a1a4b Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 10 Jul 2014 22:28:22 -0500 Subject: [PATCH] Use chan struct{} for tx/blockProcessed chans. These channels are being used as semaphores, so it's more efficient to use a 0-byte type and allow compiler optimizations for the specific use case. --- blockmanager.go | 8 ++++---- peer.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/blockmanager.go b/blockmanager.go index 8408e87a..e22622f3 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -1018,11 +1018,11 @@ out: case *txMsg: b.handleTxMsg(msg) - msg.peer.txProcessed <- true + msg.peer.txProcessed <- struct{}{} case *blockMsg: b.handleBlockMsg(msg) - msg.peer.blockProcessed <- true + msg.peer.blockProcessed <- struct{}{} case *invMsg: b.handleInvMsg(msg) @@ -1189,7 +1189,7 @@ func (b *blockManager) NewPeer(p *peer) { func (b *blockManager) QueueTx(tx *btcutil.Tx, p *peer) { // Don't accept more transactions if we're shutting down. if atomic.LoadInt32(&b.shutdown) != 0 { - p.txProcessed <- false + p.txProcessed <- struct{}{} return } @@ -1200,7 +1200,7 @@ func (b *blockManager) QueueTx(tx *btcutil.Tx, p *peer) { func (b *blockManager) QueueBlock(block *btcutil.Block, p *peer) { // Don't accept more blocks if we're shutting down. if atomic.LoadInt32(&b.shutdown) != 0 { - p.blockProcessed <- false + p.blockProcessed <- struct{}{} return } diff --git a/peer.go b/peer.go index dee954a5..895e887e 100644 --- a/peer.go +++ b/peer.go @@ -168,8 +168,8 @@ type peer struct { sendDoneQueue chan struct{} queueWg sync.WaitGroup // TODO(oga) wg -> single use channel? outputInvChan chan *btcwire.InvVect - txProcessed chan bool - blockProcessed chan bool + txProcessed chan struct{} + blockProcessed chan struct{} quit chan struct{} StatsMtx sync.Mutex // protects all statistics below here. versionKnown bool @@ -1795,8 +1795,8 @@ func newPeerBase(s *server, inbound bool) *peer { sendQueue: make(chan outMsg, 1), // nonblocking sync sendDoneQueue: make(chan struct{}, 1), // nonblocking sync outputInvChan: make(chan *btcwire.InvVect, outputBufferSize), - txProcessed: make(chan bool, 1), - blockProcessed: make(chan bool, 1), + txProcessed: make(chan struct{}, 1), + blockProcessed: make(chan struct{}, 1), quit: make(chan struct{}), } return &p