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
b750cab5
Unverified
Commit
b750cab5
authored
Dec 13, 2016
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
miner: fix a race between remote agent start/loop
parent
a98e8c08
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
11 deletions
+14
-11
remote_agent.go
miner/remote_agent.go
+14
-11
No files found.
miner/remote_agent.go
View file @
b750cab5
...
@@ -37,7 +37,7 @@ type hashrate struct {
...
@@ -37,7 +37,7 @@ type hashrate struct {
type
RemoteAgent
struct
{
type
RemoteAgent
struct
{
mu
sync
.
Mutex
mu
sync
.
Mutex
quit
chan
struct
{}
quit
Ch
chan
struct
{}
workCh
chan
*
Work
workCh
chan
*
Work
returnCh
chan
<-
*
Result
returnCh
chan
<-
*
Result
...
@@ -76,18 +76,16 @@ func (a *RemoteAgent) Start() {
...
@@ -76,18 +76,16 @@ func (a *RemoteAgent) Start() {
if
!
atomic
.
CompareAndSwapInt32
(
&
a
.
running
,
0
,
1
)
{
if
!
atomic
.
CompareAndSwapInt32
(
&
a
.
running
,
0
,
1
)
{
return
return
}
}
a
.
quitCh
=
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
.
loop
(
a
.
workCh
,
a
.
quitCh
)
}
}
func
(
a
*
RemoteAgent
)
Stop
()
{
func
(
a
*
RemoteAgent
)
Stop
()
{
if
!
atomic
.
CompareAndSwapInt32
(
&
a
.
running
,
1
,
0
)
{
if
!
atomic
.
CompareAndSwapInt32
(
&
a
.
running
,
1
,
0
)
{
return
return
}
}
close
(
a
.
quitCh
)
close
(
a
.
quit
)
close
(
a
.
workCh
)
close
(
a
.
workCh
)
}
}
...
@@ -148,15 +146,20 @@ func (a *RemoteAgent) SubmitWork(nonce uint64, mixDigest, hash common.Hash) bool
...
@@ -148,15 +146,20 @@ func (a *RemoteAgent) SubmitWork(nonce uint64, mixDigest, hash common.Hash) bool
return
false
return
false
}
}
func
(
a
*
RemoteAgent
)
maintainLoop
()
{
// loop monitors mining events on the work and quit channels, updating the internal
// state of the rmeote miner until a termination is requested.
//
// Note, the reason the work and quit channels are passed as parameters is because
// RemoteAgent.Start() constantly recreates these channels, so the loop code cannot
// assume data stability in these member fields.
func
(
a
*
RemoteAgent
)
loop
(
workCh
chan
*
Work
,
quitCh
chan
struct
{})
{
ticker
:=
time
.
Tick
(
5
*
time
.
Second
)
ticker
:=
time
.
Tick
(
5
*
time
.
Second
)
out
:
for
{
for
{
select
{
select
{
case
<-
a
.
quit
:
case
<-
quitCh
:
break
out
return
case
work
:=
<-
a
.
workCh
:
case
work
:=
<-
workCh
:
a
.
mu
.
Lock
()
a
.
mu
.
Lock
()
a
.
currentWork
=
work
a
.
currentWork
=
work
a
.
mu
.
Unlock
()
a
.
mu
.
Unlock
()
...
...
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