aboutsummaryrefslogtreecommitdiffstats
path: root/miner
diff options
context:
space:
mode:
author☃ Elliot Shepherd <elliot@identitii.com>2016-08-25 22:12:17 +0800
committer☃ Elliot Shepherd <elliot@identitii.com>2016-08-25 22:12:17 +0800
commitac0f8b81ae40f18a70413916e5ef1cbc503e4743 (patch)
tree1e4d69b26f3f43cbeb27219c72ee428517f539fc /miner
parent806e3cd0751e7769bddbb2d4250b4520d912df42 (diff)
downloadgo-tangerine-ac0f8b81ae40f18a70413916e5ef1cbc503e4743.tar
go-tangerine-ac0f8b81ae40f18a70413916e5ef1cbc503e4743.tar.gz
go-tangerine-ac0f8b81ae40f18a70413916e5ef1cbc503e4743.tar.bz2
go-tangerine-ac0f8b81ae40f18a70413916e5ef1cbc503e4743.tar.lz
go-tangerine-ac0f8b81ae40f18a70413916e5ef1cbc503e4743.tar.xz
go-tangerine-ac0f8b81ae40f18a70413916e5ef1cbc503e4743.tar.zst
go-tangerine-ac0f8b81ae40f18a70413916e5ef1cbc503e4743.zip
miner: Move CpuAgent channel creation from Start() to initialization (fixes #2948)
Also remove the now un-needed mutex locking in Start() and Stop()
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()
}