[#1157] network/cache: Optimize `client` fetch from `multiClient`
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>remotes/KirillovDenis/master
parent
a4261243fc
commit
2a69aaf976
|
@ -235,16 +235,21 @@ func (x *multiClient) RawForAddress(addr network.Address, f func(client *rawclie
|
|||
}
|
||||
|
||||
func (x *multiClient) client(addr network.Address) clientcore.Client {
|
||||
x.mtx.Lock()
|
||||
|
||||
strAddr := addr.String()
|
||||
|
||||
x.mtx.RLock()
|
||||
c, cached := x.clients[strAddr]
|
||||
if !cached {
|
||||
c = x.createForAddress(addr)
|
||||
}
|
||||
x.mtx.RUnlock()
|
||||
|
||||
x.mtx.Unlock()
|
||||
if !cached {
|
||||
x.mtx.Lock()
|
||||
|
||||
c, cached = x.clients[strAddr]
|
||||
if !cached {
|
||||
c = x.createForAddress(addr)
|
||||
}
|
||||
x.mtx.Unlock()
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue