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
d14c07d9
Unverified
Commit
d14c07d9
authored
1 year ago
by
ucwong
Committed by
GitHub
1 year ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts: use atomic type (#27857)
parent
85747675
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
9 deletions
+9
-9
keystore_test.go
accounts/keystore/keystore_test.go
+3
-3
hub.go
accounts/usbwallet/hub.go
+6
-6
No files found.
accounts/keystore/keystore_test.go
View file @
d14c07d9
...
...
@@ -397,19 +397,19 @@ func TestImportRace(t *testing.T) {
t
.
Fatalf
(
"failed to export account: %v"
,
acc
)
}
_
,
ks2
:=
tmpKeyStore
(
t
,
true
)
var
atom
u
int32
var
atom
atomic
.
U
int32
var
wg
sync
.
WaitGroup
wg
.
Add
(
2
)
for
i
:=
0
;
i
<
2
;
i
++
{
go
func
()
{
defer
wg
.
Done
()
if
_
,
err
:=
ks2
.
Import
(
json
,
"new"
,
"new"
);
err
!=
nil
{
atom
ic
.
AddUint32
(
&
atom
,
1
)
atom
.
Add
(
1
)
}
}()
}
wg
.
Wait
()
if
atom
!=
1
{
if
atom
.
Load
()
!=
1
{
t
.
Errorf
(
"Import is racy"
)
}
}
...
...
This diff is collapsed.
Click to expand it.
accounts/usbwallet/hub.go
View file @
d14c07d9
...
...
@@ -63,9 +63,9 @@ type Hub struct {
stateLock
sync
.
RWMutex
// Protects the internals of the hub from racey access
// TODO(karalabe): remove if hotplug lands on Windows
commsPend
int
// Number of operations blocking enumeration
commsLock
sync
.
Mutex
// Lock protecting the pending counter and enumeration
enumFails
uint32
// Number of times enumeration has failed
commsPend
int
// Number of operations blocking enumeration
commsLock
sync
.
Mutex
// Lock protecting the pending counter and enumeration
enumFails
atomic
.
Uint32
// Number of times enumeration has failed
}
// NewLedgerHub creates a new hardware wallet manager for Ledger devices.
...
...
@@ -151,7 +151,7 @@ func (hub *Hub) refreshWallets() {
return
}
// If USB enumeration is continually failing, don't keep trying indefinitely
if
atomic
.
LoadUint32
(
&
hub
.
enumFails
)
>
2
{
if
hub
.
enumFails
.
Load
(
)
>
2
{
return
}
// Retrieve the current list of USB wallet devices
...
...
@@ -172,7 +172,7 @@ func (hub *Hub) refreshWallets() {
}
infos
,
err
:=
usb
.
Enumerate
(
hub
.
vendorID
,
0
)
if
err
!=
nil
{
failcount
:=
atomic
.
AddUint32
(
&
hub
.
enumFails
,
1
)
failcount
:=
hub
.
enumFails
.
Add
(
1
)
if
runtime
.
GOOS
==
"linux"
{
// See rationale before the enumeration why this is needed and only on Linux.
hub
.
commsLock
.
Unlock
()
...
...
@@ -181,7 +181,7 @@ func (hub *Hub) refreshWallets() {
"vendor"
,
hub
.
vendorID
,
"failcount"
,
failcount
,
"err"
,
err
)
return
}
atomic
.
StoreUint32
(
&
hub
.
enumFails
,
0
)
hub
.
enumFails
.
Store
(
0
)
for
_
,
info
:=
range
infos
{
for
_
,
id
:=
range
hub
.
productIDs
{
...
...
This diff is collapsed.
Click to expand it.
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