perf(mux) use RWMutex
Brian Tiger Chow committed
Oct 27, 2014 at 20:36 UTC
ed0556b9196dab421dee21d08680b28fb00f7f95
1 file changed
+6
-6
net/mux/mux.go
+6
-6
@@ -41,10 +41,10 @@ type Muxer struct {
41
// Protocols are the multiplexed services.
42
Protocols ProtocolMap
43
44
- bwiLock sync.Mutex
44
+ bwiLock sync.RWMutex
45
bwIn uint64
46
47
- bwoLock sync.Mutex
47
+ bwoLock sync.RWMutex
48
bwOut uint64
49
50
*msg.Pipe
@@ -76,13 +76,13 @@ func (m *Muxer) GetPipe() *msg.Pipe {
76
77
// GetBandwidthTotals return the in/out bandwidth measured over this muxer.
78
func (m *Muxer) GetBandwidthTotals() (in uint64, out uint64) {
79
- m.bwiLock.Lock()
79
+ m.bwiLock.RLock()
80
in = m.bwIn
81
- m.bwiLock.Unlock()
81
+ m.bwiLock.RUnlock()
82
83
- m.bwoLock.Lock()
83
+ m.bwoLock.RLock()
84
out = m.bwOut
85
- m.bwoLock.Unlock()
85
+ m.bwoLock.RUnlock()
86
return
87
}
88