diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-11-01 03:00:34 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-11-01 03:00:34 +0800 |
commit | c841e39476777d0be14f04fc3a1c69f51df84933 (patch) | |
tree | d9401a501076932c010c2e5ec590ef5bbfc38ef0 | |
parent | 016ad3e96215a7bdd309bbef847f9dcf4674b8e9 (diff) | |
parent | 8c38f8d81529ada04fde4e3d41530aa61b477792 (diff) | |
download | go-tangerine-c841e39476777d0be14f04fc3a1c69f51df84933.tar go-tangerine-c841e39476777d0be14f04fc3a1c69f51df84933.tar.gz go-tangerine-c841e39476777d0be14f04fc3a1c69f51df84933.tar.bz2 go-tangerine-c841e39476777d0be14f04fc3a1c69f51df84933.tar.lz go-tangerine-c841e39476777d0be14f04fc3a1c69f51df84933.tar.xz go-tangerine-c841e39476777d0be14f04fc3a1c69f51df84933.tar.zst go-tangerine-c841e39476777d0be14f04fc3a1c69f51df84933.zip |
Merge pull request #1954 from obscuren/regression-miner
miner: synchronise start / stop
-rw-r--r-- | miner/remote_agent.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/miner/remote_agent.go b/miner/remote_agent.go index 18ddf121c..00b5f7e08 100644 --- a/miner/remote_agent.go +++ b/miner/remote_agent.go @@ -20,6 +20,7 @@ import ( "errors" "math/big" "sync" + "sync/atomic" "time" "github.com/ethereum/ethash" @@ -45,6 +46,8 @@ type RemoteAgent struct { hashrateMu sync.RWMutex hashrate map[common.Hash]hashrate + + running int32 // running indicates whether the agent is active. Call atomically } func NewRemoteAgent() *RemoteAgent { @@ -70,18 +73,22 @@ func (a *RemoteAgent) SetReturnCh(returnCh chan<- *Result) { } func (a *RemoteAgent) Start() { + if !atomic.CompareAndSwapInt32(&a.running, 0, 1) { + return + } + a.quit = make(chan struct{}) a.workCh = make(chan *Work, 1) go a.maintainLoop() } func (a *RemoteAgent) Stop() { - if a.quit != nil { - close(a.quit) - } - if a.workCh != nil { - close(a.workCh) + if !atomic.CompareAndSwapInt32(&a.running, 1, 0) { + return } + + close(a.quit) + close(a.workCh) } // GetHashRate returns the accumulated hashrate of all identifier combined |