forked from cerc-io/plugeth
miner: Move CpuAgent channel creation from Start() to initialization (fixes #2948)
Also remove the now un-needed mutex locking in Start() and Stop()
This commit is contained in:
parent
806e3cd075
commit
ac0f8b81ae
@ -45,6 +45,8 @@ func NewCpuAgent(index int, pow pow.PoW) *CpuAgent {
|
||||
miner := &CpuAgent{
|
||||
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()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user