File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import (
23
23
"github.com/ethereum/go-ethereum/logger"
24
24
"github.com/ethereum/go-ethereum/logger/glog"
25
25
"github.com/ethereum/go-ethereum/pow"
26
+ "sync/atomic"
26
27
)
27
28
28
29
type CpuAgent struct {
@@ -35,6 +36,8 @@ type CpuAgent struct {
35
36
36
37
index int
37
38
pow pow.PoW
39
+
40
+ isMining int32 // isMining indicates whether the agent is currently mining
38
41
}
39
42
40
43
func NewCpuAgent (index int , pow pow.PoW ) * CpuAgent {
@@ -60,6 +63,10 @@ func (self *CpuAgent) Stop() {
60
63
func (self * CpuAgent ) Start () {
61
64
self .mu .Lock ()
62
65
defer self .mu .Unlock ()
66
+
67
+ if ! atomic .CompareAndSwapInt32 (& self .isMining , 0 , 1 ) {
68
+ return // agent already started
69
+ }
63
70
64
71
self .quit = make (chan struct {})
65
72
// creating current op ch makes sure we're not closing a nil ch
@@ -99,10 +106,11 @@ done:
99
106
case <- self .workCh :
100
107
default :
101
108
close (self .workCh )
102
-
103
109
break done
104
110
}
105
111
}
112
+
113
+ atomic .StoreInt32 (& self .isMining , 0 )
106
114
}
107
115
108
116
func (self * CpuAgent ) mine (work * Work , stop <- chan struct {}) {
You can’t perform that action at this time.
0 commit comments