提交 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 {
// 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
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论