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.
This commit is contained in:
parent
1483b92dcf
commit
83cffc5d27
2 changed files with 8 additions and 8 deletions
|
@ -1018,11 +1018,11 @@ out:
|
||||||
|
|
||||||
case *txMsg:
|
case *txMsg:
|
||||||
b.handleTxMsg(msg)
|
b.handleTxMsg(msg)
|
||||||
msg.peer.txProcessed <- true
|
msg.peer.txProcessed <- struct{}{}
|
||||||
|
|
||||||
case *blockMsg:
|
case *blockMsg:
|
||||||
b.handleBlockMsg(msg)
|
b.handleBlockMsg(msg)
|
||||||
msg.peer.blockProcessed <- true
|
msg.peer.blockProcessed <- struct{}{}
|
||||||
|
|
||||||
case *invMsg:
|
case *invMsg:
|
||||||
b.handleInvMsg(msg)
|
b.handleInvMsg(msg)
|
||||||
|
@ -1189,7 +1189,7 @@ func (b *blockManager) NewPeer(p *peer) {
|
||||||
func (b *blockManager) QueueTx(tx *btcutil.Tx, p *peer) {
|
func (b *blockManager) QueueTx(tx *btcutil.Tx, p *peer) {
|
||||||
// Don't accept more transactions if we're shutting down.
|
// Don't accept more transactions if we're shutting down.
|
||||||
if atomic.LoadInt32(&b.shutdown) != 0 {
|
if atomic.LoadInt32(&b.shutdown) != 0 {
|
||||||
p.txProcessed <- false
|
p.txProcessed <- struct{}{}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1200,7 +1200,7 @@ func (b *blockManager) QueueTx(tx *btcutil.Tx, p *peer) {
|
||||||
func (b *blockManager) QueueBlock(block *btcutil.Block, p *peer) {
|
func (b *blockManager) QueueBlock(block *btcutil.Block, p *peer) {
|
||||||
// Don't accept more blocks if we're shutting down.
|
// Don't accept more blocks if we're shutting down.
|
||||||
if atomic.LoadInt32(&b.shutdown) != 0 {
|
if atomic.LoadInt32(&b.shutdown) != 0 {
|
||||||
p.blockProcessed <- false
|
p.blockProcessed <- struct{}{}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
peer.go
8
peer.go
|
@ -168,8 +168,8 @@ type peer struct {
|
||||||
sendDoneQueue chan struct{}
|
sendDoneQueue chan struct{}
|
||||||
queueWg sync.WaitGroup // TODO(oga) wg -> single use channel?
|
queueWg sync.WaitGroup // TODO(oga) wg -> single use channel?
|
||||||
outputInvChan chan *btcwire.InvVect
|
outputInvChan chan *btcwire.InvVect
|
||||||
txProcessed chan bool
|
txProcessed chan struct{}
|
||||||
blockProcessed chan bool
|
blockProcessed chan struct{}
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
StatsMtx sync.Mutex // protects all statistics below here.
|
StatsMtx sync.Mutex // protects all statistics below here.
|
||||||
versionKnown bool
|
versionKnown bool
|
||||||
|
@ -1795,8 +1795,8 @@ func newPeerBase(s *server, inbound bool) *peer {
|
||||||
sendQueue: make(chan outMsg, 1), // nonblocking sync
|
sendQueue: make(chan outMsg, 1), // nonblocking sync
|
||||||
sendDoneQueue: make(chan struct{}, 1), // nonblocking sync
|
sendDoneQueue: make(chan struct{}, 1), // nonblocking sync
|
||||||
outputInvChan: make(chan *btcwire.InvVect, outputBufferSize),
|
outputInvChan: make(chan *btcwire.InvVect, outputBufferSize),
|
||||||
txProcessed: make(chan bool, 1),
|
txProcessed: make(chan struct{}, 1),
|
||||||
blockProcessed: make(chan bool, 1),
|
blockProcessed: make(chan struct{}, 1),
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
}
|
}
|
||||||
return &p
|
return &p
|
||||||
|
|
Loading…
Reference in a new issue