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
96e2b6bc
Commit
96e2b6bc
authored
Apr 22, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
miner: use 32bit atomic operations
64bit atomic operations are not available on all 32bit platforms.
parent
9d152d61
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
11 deletions
+12
-11
worker.go
miner/worker.go
+12
-11
No files found.
miner/worker.go
View file @
96e2b6bc
...
@@ -66,7 +66,6 @@ type worker struct {
...
@@ -66,7 +66,6 @@ type worker struct {
mux
*
event
.
TypeMux
mux
*
event
.
TypeMux
quit
chan
struct
{}
quit
chan
struct
{}
pow
pow
.
PoW
pow
pow
.
PoW
atWork
int64
eth
core
.
Backend
eth
core
.
Backend
chain
*
core
.
ChainManager
chain
*
core
.
ChainManager
...
@@ -84,7 +83,9 @@ type worker struct {
...
@@ -84,7 +83,9 @@ type worker struct {
txQueueMu
sync
.
Mutex
txQueueMu
sync
.
Mutex
txQueue
map
[
common
.
Hash
]
*
types
.
Transaction
txQueue
map
[
common
.
Hash
]
*
types
.
Transaction
mining
int64
// atomic status counters
mining
int32
atWork
int32
}
}
func
newWorker
(
coinbase
common
.
Address
,
eth
core
.
Backend
)
*
worker
{
func
newWorker
(
coinbase
common
.
Address
,
eth
core
.
Backend
)
*
worker
{
...
@@ -127,19 +128,19 @@ func (self *worker) start() {
...
@@ -127,19 +128,19 @@ func (self *worker) start() {
agent
.
Start
()
agent
.
Start
()
}
}
atomic
.
StoreInt
64
(
&
self
.
mining
,
1
)
atomic
.
StoreInt
32
(
&
self
.
mining
,
1
)
}
}
func
(
self
*
worker
)
stop
()
{
func
(
self
*
worker
)
stop
()
{
if
atomic
.
LoadInt
64
(
&
self
.
mining
)
==
1
{
if
atomic
.
LoadInt
32
(
&
self
.
mining
)
==
1
{
// stop all agents
// stop all agents
for
_
,
agent
:=
range
self
.
agents
{
for
_
,
agent
:=
range
self
.
agents
{
agent
.
Stop
()
agent
.
Stop
()
}
}
}
}
atomic
.
StoreInt
64
(
&
self
.
mining
,
0
)
atomic
.
StoreInt
32
(
&
self
.
mining
,
0
)
atomic
.
StoreInt
64
(
&
self
.
atWork
,
0
)
atomic
.
StoreInt
32
(
&
self
.
atWork
,
0
)
}
}
func
(
self
*
worker
)
register
(
agent
Agent
)
{
func
(
self
*
worker
)
register
(
agent
Agent
)
{
...
@@ -162,7 +163,7 @@ out:
...
@@ -162,7 +163,7 @@ out:
self
.
possibleUncles
[
ev
.
Block
.
Hash
()]
=
ev
.
Block
self
.
possibleUncles
[
ev
.
Block
.
Hash
()]
=
ev
.
Block
self
.
uncleMu
.
Unlock
()
self
.
uncleMu
.
Unlock
()
case
core
.
TxPreEvent
:
case
core
.
TxPreEvent
:
if
atomic
.
LoadInt
64
(
&
self
.
mining
)
==
0
{
if
atomic
.
LoadInt
32
(
&
self
.
mining
)
==
0
{
self
.
commitNewWork
()
self
.
commitNewWork
()
}
}
}
}
...
@@ -177,7 +178,7 @@ out:
...
@@ -177,7 +178,7 @@ out:
func
(
self
*
worker
)
wait
()
{
func
(
self
*
worker
)
wait
()
{
for
{
for
{
for
block
:=
range
self
.
recv
{
for
block
:=
range
self
.
recv
{
atomic
.
AddInt
64
(
&
self
.
atWork
,
-
1
)
atomic
.
AddInt
32
(
&
self
.
atWork
,
-
1
)
if
block
==
nil
{
if
block
==
nil
{
continue
continue
...
@@ -205,13 +206,13 @@ func (self *worker) wait() {
...
@@ -205,13 +206,13 @@ func (self *worker) wait() {
}
}
func
(
self
*
worker
)
push
()
{
func
(
self
*
worker
)
push
()
{
if
atomic
.
LoadInt
64
(
&
self
.
mining
)
==
1
{
if
atomic
.
LoadInt
32
(
&
self
.
mining
)
==
1
{
self
.
current
.
block
.
Header
()
.
GasUsed
=
self
.
current
.
totalUsedGas
self
.
current
.
block
.
Header
()
.
GasUsed
=
self
.
current
.
totalUsedGas
self
.
current
.
block
.
SetRoot
(
self
.
current
.
state
.
Root
())
self
.
current
.
block
.
SetRoot
(
self
.
current
.
state
.
Root
())
// push new work to agents
// push new work to agents
for
_
,
agent
:=
range
self
.
agents
{
for
_
,
agent
:=
range
self
.
agents
{
atomic
.
AddInt
64
(
&
self
.
atWork
,
1
)
atomic
.
AddInt
32
(
&
self
.
atWork
,
1
)
if
agent
.
Work
()
!=
nil
{
if
agent
.
Work
()
!=
nil
{
agent
.
Work
()
<-
self
.
current
.
block
.
Copy
()
agent
.
Work
()
<-
self
.
current
.
block
.
Copy
()
...
@@ -320,7 +321,7 @@ func (self *worker) commitNewWork() {
...
@@ -320,7 +321,7 @@ func (self *worker) commitNewWork() {
}
}
// We only care about logging if we're actually mining
// We only care about logging if we're actually mining
if
atomic
.
LoadInt
64
(
&
self
.
mining
)
==
1
{
if
atomic
.
LoadInt
32
(
&
self
.
mining
)
==
1
{
glog
.
V
(
logger
.
Info
)
.
Infof
(
"commit new work on block %v with %d txs & %d uncles
\n
"
,
self
.
current
.
block
.
Number
(),
tcount
,
len
(
uncles
))
glog
.
V
(
logger
.
Info
)
.
Infof
(
"commit new work on block %v with %d txs & %d uncles
\n
"
,
self
.
current
.
block
.
Number
(),
tcount
,
len
(
uncles
))
}
}
...
...
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