good morning!!!!

Skip to content
Snippets Groups Projects
Commit 8c38f8d8 authored by Jeffrey Wilcke's avatar Jeffrey Wilcke
Browse files

miner: synchronise start / stop

This PR fixes an issue where the remote worker was stopped twice and not
properly handled. This adds a synchronised running check to the start
and stop methods preventing closing of a channel more than once.
parent 016ad3e9
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ import ( ...@@ -20,6 +20,7 @@ import (
"errors" "errors"
"math/big" "math/big"
"sync" "sync"
"sync/atomic"
"time" "time"
"github.com/ethereum/ethash" "github.com/ethereum/ethash"
...@@ -45,6 +46,8 @@ type RemoteAgent struct { ...@@ -45,6 +46,8 @@ type RemoteAgent struct {
hashrateMu sync.RWMutex hashrateMu sync.RWMutex
hashrate map[common.Hash]hashrate hashrate map[common.Hash]hashrate
running int32 // running indicates whether the agent is active. Call atomically
} }
func NewRemoteAgent() *RemoteAgent { func NewRemoteAgent() *RemoteAgent {
...@@ -70,19 +73,23 @@ func (a *RemoteAgent) SetReturnCh(returnCh chan<- *Result) { ...@@ -70,19 +73,23 @@ func (a *RemoteAgent) SetReturnCh(returnCh chan<- *Result) {
} }
func (a *RemoteAgent) Start() { func (a *RemoteAgent) Start() {
if !atomic.CompareAndSwapInt32(&a.running, 0, 1) {
return
}
a.quit = make(chan struct{}) a.quit = make(chan struct{})
a.workCh = make(chan *Work, 1) a.workCh = make(chan *Work, 1)
go a.maintainLoop() go a.maintainLoop()
} }
func (a *RemoteAgent) Stop() { func (a *RemoteAgent) Stop() {
if a.quit != nil { if !atomic.CompareAndSwapInt32(&a.running, 1, 0) {
close(a.quit) return
} }
if a.workCh != nil {
close(a.quit)
close(a.workCh) close(a.workCh)
} }
}
// GetHashRate returns the accumulated hashrate of all identifier combined // GetHashRate returns the accumulated hashrate of all identifier combined
func (a *RemoteAgent) GetHashRate() (tot int64) { func (a *RemoteAgent) GetHashRate() (tot int64) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment