aboutsummaryrefslogtreecommitdiffstats
path: root/miner
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-09-02 19:45:15 +0800
committerGitHub <noreply@github.com>2016-09-02 19:45:15 +0800
commit2c6be49d200a3fff660ad78aada3305f8a3e3b9a (patch)
tree2f35733a50f9c06c65193593ccba316f96dba742 /miner
parenta42b7355f40fbc58893ca074db818d461083912c (diff)
parentac0f8b81ae40f18a70413916e5ef1cbc503e4743 (diff)
downloaddexon-2c6be49d200a3fff660ad78aada3305f8a3e3b9a.tar.gz
dexon-2c6be49d200a3fff660ad78aada3305f8a3e3b9a.tar.zst
dexon-2c6be49d200a3fff660ad78aada3305f8a3e3b9a.zip
Merge pull request #2949 from elliots/fix/#2948
miner: Prevent attempts to close nil quit channel in agent (fixes #2948)
Diffstat (limited to 'miner')
-rw-r--r--miner/agent.go16
1 files changed, 4 insertions, 12 deletions
diff --git a/miner/agent.go b/miner/agent.go
index 4a4683bc6..16f2a7723 100644
--- a/miner/agent.go
+++ b/miner/agent.go
@@ -43,8 +43,10 @@ type CpuAgent struct {
func NewCpuAgent(index int, pow pow.PoW) *CpuAgent {
miner := &CpuAgent{
- pow: pow,
- index: index,
+ pow: pow,
+ index: index,
+ quit: make(chan struct{}),
+ workCh: make(chan *Work, 1),
}
return miner
@@ -55,25 +57,15 @@ func (self *CpuAgent) Pow() pow.PoW { return self.pow }
func (self *CpuAgent) SetReturnCh(ch chan<- *Result) { self.returnCh = ch }
func (self *CpuAgent) Stop() {
- self.mu.Lock()
- defer self.mu.Unlock()
-
close(self.quit)
}
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
- // later on
- self.workCh = make(chan *Work, 1)
-
go self.update()
}