File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
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 {
@@ -58,15 +61,21 @@ func (self *CpuAgent) Stop() {
58
61
}
59
62
60
63
func (self * CpuAgent ) Start () {
61
- self .mu .Lock ()
62
64
defer self .mu .Unlock ()
65
+ self .mu .Lock ()
66
+
67
+ if atomic .LoadInt32 (& self .isMining ) == 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
66
73
// later on
67
74
self .workCh = make (chan * Work , 1 )
68
75
69
76
go self .update ()
77
+
78
+ atomic .StoreInt32 (& self .isMining , 1 )
70
79
}
71
80
72
81
func (self * CpuAgent ) update () {
@@ -99,10 +108,11 @@ done:
99
108
case <- self .workCh :
100
109
default :
101
110
close (self .workCh )
102
-
103
111
break done
104
112
}
105
113
}
114
+
115
+ atomic .StoreInt32 (& self .isMining , 0 )
106
116
}
107
117
108
118
func (self * CpuAgent ) mine (work * Work , stop <- chan struct {}) {
You can’t perform that action at this time.
0 commit comments