mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 10:49:24 +08:00
perf(mux) use RWMutex
This commit is contained in:
@ -41,10 +41,10 @@ type Muxer struct {
|
||||
// Protocols are the multiplexed services.
|
||||
Protocols ProtocolMap
|
||||
|
||||
bwiLock sync.Mutex
|
||||
bwiLock sync.RWMutex
|
||||
bwIn uint64
|
||||
|
||||
bwoLock sync.Mutex
|
||||
bwoLock sync.RWMutex
|
||||
bwOut uint64
|
||||
|
||||
*msg.Pipe
|
||||
@ -76,13 +76,13 @@ func (m *Muxer) GetPipe() *msg.Pipe {
|
||||
|
||||
// GetBandwidthTotals return the in/out bandwidth measured over this muxer.
|
||||
func (m *Muxer) GetBandwidthTotals() (in uint64, out uint64) {
|
||||
m.bwiLock.Lock()
|
||||
m.bwiLock.RLock()
|
||||
in = m.bwIn
|
||||
m.bwiLock.Unlock()
|
||||
m.bwiLock.RUnlock()
|
||||
|
||||
m.bwoLock.Lock()
|
||||
m.bwoLock.RLock()
|
||||
out = m.bwOut
|
||||
m.bwoLock.Unlock()
|
||||
m.bwoLock.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user