aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-09-09 19:49:28 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-09-09 19:49:28 +0800
commit28b13a4d1e0be7b14d23efdbe08b7ae133008ce8 (patch)
tree8fbbf904ed1b32b8fd5d60ad950b82c015aad70c
parentedaea698172feecc6130938c8d6197f8653c0a83 (diff)
parent652eea71febb8ae39cde9d72c1d4a74e193ec55e (diff)
downloaddexon-28b13a4d1e0be7b14d23efdbe08b7ae133008ce8.tar.gz
dexon-28b13a4d1e0be7b14d23efdbe08b7ae133008ce8.tar.zst
dexon-28b13a4d1e0be7b14d23efdbe08b7ae133008ce8.zip
Merge pull request #1780 from bas-vk/miner-crash
agent/miner Prevent the CpuAgent to be started multiple times
-rw-r--r--miner/agent.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/miner/agent.go b/miner/agent.go
index 2f8d9fee4..7ccf8d2e0 100644
--- a/miner/agent.go
+++ b/miner/agent.go
@@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/pow"
+ "sync/atomic"
)
type CpuAgent struct {
@@ -35,6 +36,8 @@ type CpuAgent struct {
index int
pow pow.PoW
+
+ isMining int32 // isMining indicates whether the agent is currently mining
}
func NewCpuAgent(index int, pow pow.PoW) *CpuAgent {
@@ -60,6 +63,10 @@ func (self *CpuAgent) Stop() {
func (self *CpuAgent) Start() {
self.mu.Lock()
defer self.mu.Unlock()
+
+ if !atomic.CompareAndSwapInt32(&self.isMining, 0, 1) {
+ return // agent already started
+ }
self.quit = make(chan struct{})
// creating current op ch makes sure we're not closing a nil ch
@@ -99,10 +106,11 @@ done:
case <-self.workCh:
default:
close(self.workCh)
-
break done
}
}
+
+ atomic.StoreInt32(&self.isMining, 0)
}
func (self *CpuAgent) mine(work *Work, stop <-chan struct{}) {