aboutsummaryrefslogtreecommitdiffstats
path: root/miner
diff options
context:
space:
mode:
authorMark <markya0616@gmail.com>2017-09-19 19:28:15 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-09-19 19:28:15 +0800
commitcb5235eb0767c4de4ba6cc94cf8283421b2179c1 (patch)
tree3b59ab5f7c0f28907425b580b431d18b1108be14 /miner
parenta92d8a26547c138953665387c57168e68bacdd13 (diff)
downloaddexon-cb5235eb0767c4de4ba6cc94cf8283421b2179c1.tar
dexon-cb5235eb0767c4de4ba6cc94cf8283421b2179c1.tar.gz
dexon-cb5235eb0767c4de4ba6cc94cf8283421b2179c1.tar.bz2
dexon-cb5235eb0767c4de4ba6cc94cf8283421b2179c1.tar.lz
dexon-cb5235eb0767c4de4ba6cc94cf8283421b2179c1.tar.xz
dexon-cb5235eb0767c4de4ba6cc94cf8283421b2179c1.tar.zst
dexon-cb5235eb0767c4de4ba6cc94cf8283421b2179c1.zip
miner: make starting of CPU agent more reliable (#15148)
Diffstat (limited to 'miner')
-rw-r--r--miner/agent.go23
1 files changed, 12 insertions, 11 deletions
diff --git a/miner/agent.go b/miner/agent.go
index 855892a07..e3cebbd2e 100644
--- a/miner/agent.go
+++ b/miner/agent.go
@@ -53,7 +53,19 @@ func (self *CpuAgent) Work() chan<- *Work { return self.workCh }
func (self *CpuAgent) SetReturnCh(ch chan<- *Result) { self.returnCh = ch }
func (self *CpuAgent) Stop() {
+ if !atomic.CompareAndSwapInt32(&self.isMining, 1, 0) {
+ return // agent already stopped
+ }
self.stop <- struct{}{}
+done:
+ // Empty work channel
+ for {
+ select {
+ case <-self.workCh:
+ default:
+ break done
+ }
+ }
}
func (self *CpuAgent) Start() {
@@ -85,17 +97,6 @@ out:
break out
}
}
-
-done:
- // Empty work channel
- for {
- select {
- case <-self.workCh:
- default:
- break done
- }
- }
- atomic.StoreInt32(&self.isMining, 0)
}
func (self *CpuAgent) mine(work *Work, stop <-chan struct{}) {