Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
28b13a4d
Commit
28b13a4d
authored
Sep 09, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1780 from bas-vk/miner-crash
agent/miner Prevent the CpuAgent to be started multiple times
parents
edaea698
652eea71
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
1 deletion
+9
-1
agent.go
miner/agent.go
+9
-1
No files found.
miner/agent.go
View file @
28b13a4d
...
...
@@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/pow"
"sync/atomic"
)
type
CpuAgent
struct
{
...
...
@@ -35,6 +36,8 @@ type CpuAgent struct {
index
int
pow
pow
.
PoW
isMining
int32
// isMining indicates whether the agent is currently mining
}
func
NewCpuAgent
(
index
int
,
pow
pow
.
PoW
)
*
CpuAgent
{
...
...
@@ -60,6 +63,10 @@ func (self *CpuAgent) Stop() {
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
...
...
@@ -99,10 +106,11 @@ done:
case
<-
self
.
workCh
:
default
:
close
(
self
.
workCh
)
break
done
}
}
atomic
.
StoreInt32
(
&
self
.
isMining
,
0
)
}
func
(
self
*
CpuAgent
)
mine
(
work
*
Work
,
stop
<-
chan
struct
{})
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment