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
741fa8ca
Commit
741fa8ca
authored
May 16, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
miner: mutex locks on cpu agent. Closes #1007
parent
1564f1a0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
16 deletions
+23
-16
agent.go
miner/agent.go
+23
-16
No files found.
miner/agent.go
View file @
741fa8ca
...
...
@@ -11,8 +11,9 @@ import (
)
type
CpuAgent
struct
{
chMu
sync
.
Mutex
c
chan
*
types
.
Block
mu
sync
.
Mutex
workCh
chan
*
types
.
Block
quit
chan
struct
{}
quitCurrentOp
chan
struct
{}
returnCh
chan
<-
*
types
.
Block
...
...
@@ -30,19 +31,26 @@ func NewCpuAgent(index int, pow pow.PoW) *CpuAgent {
return
miner
}
func
(
self
*
CpuAgent
)
Work
()
chan
<-
*
types
.
Block
{
return
self
.
c
}
func
(
self
*
CpuAgent
)
Work
()
chan
<-
*
types
.
Block
{
return
self
.
workCh
}
func
(
self
*
CpuAgent
)
Pow
()
pow
.
PoW
{
return
self
.
pow
}
func
(
self
*
CpuAgent
)
SetReturnCh
(
ch
chan
<-
*
types
.
Block
)
{
self
.
returnCh
=
ch
}
func
(
self
*
CpuAgent
)
Stop
()
{
self
.
mu
.
Lock
()
defer
self
.
mu
.
Unlock
()
close
(
self
.
quit
)
close
(
self
.
quitCurrentOp
)
}
func
(
self
*
CpuAgent
)
Start
()
{
self
.
mu
.
Lock
()
defer
self
.
mu
.
Unlock
()
self
.
quit
=
make
(
chan
struct
{})
self
.
quitCurrentOp
=
make
(
chan
struct
{},
1
)
self
.
c
=
make
(
chan
*
types
.
Block
,
1
)
// creating current op ch makes sure we're not closing a nil ch
self
.
quitCurrentOp
=
make
(
chan
struct
{})
self
.
workCh
=
make
(
chan
*
types
.
Block
,
1
)
go
self
.
update
()
}
...
...
@@ -51,10 +59,10 @@ func (self *CpuAgent) update() {
out
:
for
{
select
{
case
block
:=
<-
self
.
c
:
self
.
chM
u
.
Lock
()
self
.
quitCurrentOp
<-
struct
{}{}
self
.
chM
u
.
Unlock
()
case
block
:=
<-
self
.
workCh
:
self
.
m
u
.
Lock
()
close
(
self
.
quitCurrentOp
)
self
.
m
u
.
Unlock
()
go
self
.
mine
(
block
)
case
<-
self
.
quit
:
...
...
@@ -62,14 +70,13 @@ out:
}
}
//close(self.quitCurrentOp)
done
:
// Empty channel
// Empty
work
channel
for
{
select
{
case
<-
self
.
c
:
case
<-
self
.
workCh
:
default
:
close
(
self
.
c
)
close
(
self
.
workCh
)
break
done
}
...
...
@@ -80,9 +87,9 @@ func (self *CpuAgent) mine(block *types.Block) {
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"(re)started agent[%d]. mining...
\n
"
,
self
.
index
)
// Reset the channel
self
.
chM
u
.
Lock
()
self
.
quitCurrentOp
=
make
(
chan
struct
{}
,
1
)
self
.
chM
u
.
Unlock
()
self
.
m
u
.
Lock
()
self
.
quitCurrentOp
=
make
(
chan
struct
{})
self
.
m
u
.
Unlock
()
// Mine
nonce
,
mixDigest
:=
self
.
pow
.
Search
(
block
,
self
.
quitCurrentOp
)
...
...
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