good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
741fa8ca
Commit
741fa8ca
authored
May 16, 2015
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
miner: mutex locks on cpu agent. Closes #1007
parent
1564f1a0
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
miner/agent.go
+23
-16
23 additions, 16 deletions
miner/agent.go
with
23 additions
and
16 deletions
miner/agent.go
+
23
−
16
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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment