Unverified Commit 5f2002bb authored by Boqin Qin's avatar Boqin Qin Committed by GitHub

accounts: add walletsNoLock to avoid double read lock (#20655)

parent a9614c3c
...@@ -141,6 +141,11 @@ func (am *Manager) Wallets() []Wallet { ...@@ -141,6 +141,11 @@ func (am *Manager) Wallets() []Wallet {
am.lock.RLock() am.lock.RLock()
defer am.lock.RUnlock() 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)) cpy := make([]Wallet, len(am.wallets))
copy(cpy, am.wallets) copy(cpy, am.wallets)
return cpy return cpy
...@@ -155,7 +160,7 @@ func (am *Manager) Wallet(url string) (Wallet, error) { ...@@ -155,7 +160,7 @@ func (am *Manager) Wallet(url string) (Wallet, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, wallet := range am.Wallets() { for _, wallet := range am.walletsNoLock() {
if wallet.URL() == parsed { if wallet.URL() == parsed {
return wallet, nil return wallet, nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment