1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-01 19:24:14 +08:00

perf(mux) use RWMutex

This commit is contained in:
Brian Tiger Chow
2014-10-27 20:36:45 -07:00
parent 0197fe6046
commit ed0556b919

View File

@ -41,10 +41,10 @@ type Muxer struct {
// Protocols are the multiplexed services. // Protocols are the multiplexed services.
Protocols ProtocolMap Protocols ProtocolMap
bwiLock sync.Mutex bwiLock sync.RWMutex
bwIn uint64 bwIn uint64
bwoLock sync.Mutex bwoLock sync.RWMutex
bwOut uint64 bwOut uint64
*msg.Pipe *msg.Pipe
@ -76,13 +76,13 @@ func (m *Muxer) GetPipe() *msg.Pipe {
// GetBandwidthTotals return the in/out bandwidth measured over this muxer. // GetBandwidthTotals return the in/out bandwidth measured over this muxer.
func (m *Muxer) GetBandwidthTotals() (in uint64, out uint64) { func (m *Muxer) GetBandwidthTotals() (in uint64, out uint64) {
m.bwiLock.Lock() m.bwiLock.RLock()
in = m.bwIn in = m.bwIn
m.bwiLock.Unlock() m.bwiLock.RUnlock()
m.bwoLock.Lock() m.bwoLock.RLock()
out = m.bwOut out = m.bwOut
m.bwoLock.Unlock() m.bwoLock.RUnlock()
return return
} }