core: changed interrupt strategy
Removed chain manager's select/channel approach when checking for interrupts. Now using an atomic int32 instead which checked for every block processed.
This commit is contained in:
parent
90c4493a10
commit
645dfd9693
@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"runtime"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@ -101,7 +102,8 @@ type ChainManager struct {
|
||||
futureBlocks *BlockCache
|
||||
|
||||
quit chan struct{}
|
||||
procInterupt chan struct{} // interupt signaler for block processing
|
||||
// procInterrupt must be atomically called
|
||||
procInterrupt int32 // interrupt signaler for block processing
|
||||
wg sync.WaitGroup
|
||||
|
||||
pow pow.PoW
|
||||
@ -114,7 +116,6 @@ func NewChainManager(genesis *types.Block, blockDb, stateDb common.Database, pow
|
||||
genesisBlock: GenesisBlock(42, stateDb),
|
||||
eventMux: mux,
|
||||
quit: make(chan struct{}),
|
||||
procInterupt: make(chan struct{}),
|
||||
cache: NewBlockCache(blockCacheLimit),
|
||||
pow: pow,
|
||||
}
|
||||
@ -518,7 +519,7 @@ func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error) {
|
||||
|
||||
func (bc *ChainManager) Stop() {
|
||||
close(bc.quit)
|
||||
close(bc.procInterupt)
|
||||
atomic.StoreInt32(&bc.procInterrupt, 1)
|
||||
|
||||
bc.wg.Wait()
|
||||
|
||||
@ -571,13 +572,12 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
|
||||
defer close(nonceQuit)
|
||||
|
||||
txcount := 0
|
||||
done:
|
||||
for i, block := range chain {
|
||||
select {
|
||||
case <-self.procInterupt:
|
||||
if atomic.LoadInt32(&self.procInterrupt) == 1 {
|
||||
glog.V(logger.Debug).Infoln("Premature abort during chain processing")
|
||||
break done
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
bstart := time.Now()
|
||||
// Wait for block i's nonce to be verified before processing
|
||||
// its state transition.
|
||||
@ -691,7 +691,6 @@ done:
|
||||
stats.processed++
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (stats.queued > 0 || stats.processed > 0 || stats.ignored > 0) && bool(glog.V(logger.Info)) {
|
||||
tend := time.Since(tstart)
|
||||
|
Loading…
Reference in New Issue
Block a user