Skip to content

Commit

Permalink
accounts: add walletsNoLock to avoid double read lock (#20655)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boqin Qin authored Feb 12, 2020
1 parent a9614c3 commit 5f2002b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion accounts/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ func (am *Manager) Wallets() []Wallet {
am.lock.RLock()
defer am.lock.RUnlock()

return am.walletsNoLock()
}

// walletsNoLock returns all registered wallets. Callers must hold am.lock.
func (am *Manager) walletsNoLock() []Wallet {
cpy := make([]Wallet, len(am.wallets))
copy(cpy, am.wallets)
return cpy
Expand All @@ -155,7 +160,7 @@ func (am *Manager) Wallet(url string) (Wallet, error) {
if err != nil {
return nil, err
}
for _, wallet := range am.Wallets() {
for _, wallet := range am.walletsNoLock() {
if wallet.URL() == parsed {
return wallet, nil
}
Expand Down

0 comments on commit 5f2002b

Please sign in to comment.