提交 77b6361c 作者: Juan Batiz-Benet

Merge pull request #218 from jbenet/fix/2014-10-29-mux-rwmutex

perf(mux) use RWMutex
...@@ -41,10 +41,10 @@ type Muxer struct { ...@@ -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 { ...@@ -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
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论