use an RWMutex in flowControlManager

This commit is contained in:
Lucas Clemente
2016-07-09 18:11:41 +02:00
parent 80f4a68602
commit 2d828fe6e2

View File

@@ -12,7 +12,7 @@ type flowControlManager struct {
connectionParametersManager *handshake.ConnectionParametersManager connectionParametersManager *handshake.ConnectionParametersManager
streamFlowController map[protocol.StreamID]*flowController streamFlowController map[protocol.StreamID]*flowController
contributesToConnectionFlowControl map[protocol.StreamID]bool contributesToConnectionFlowControl map[protocol.StreamID]bool
mutex sync.Mutex mutex sync.RWMutex
} }
var ( var (
@@ -139,8 +139,8 @@ func (f *flowControlManager) AddBytesSent(streamID protocol.StreamID, n protocol
// must not be called with StreamID 0 // must not be called with StreamID 0
func (f *flowControlManager) SendWindowSize(streamID protocol.StreamID) (protocol.ByteCount, error) { func (f *flowControlManager) SendWindowSize(streamID protocol.StreamID) (protocol.ByteCount, error) {
f.mutex.Lock() f.mutex.RLock()
defer f.mutex.Unlock() defer f.mutex.RUnlock()
streamFlowController, err := f.getFlowController(streamID) streamFlowController, err := f.getFlowController(streamID)
if err != nil { if err != nil {
@@ -151,6 +151,9 @@ func (f *flowControlManager) SendWindowSize(streamID protocol.StreamID) (protoco
} }
func (f *flowControlManager) RemainingConnectionWindowSize() protocol.ByteCount { func (f *flowControlManager) RemainingConnectionWindowSize() protocol.ByteCount {
f.mutex.RLock()
defer f.mutex.RUnlock()
return f.streamFlowController[0].SendWindowSize() return f.streamFlowController[0].SendWindowSize()
} }
@@ -168,8 +171,8 @@ func (f *flowControlManager) UpdateWindow(streamID protocol.StreamID, offset pro
} }
func (f *flowControlManager) StreamContributesToConnectionFlowControl(streamID protocol.StreamID) (bool, error) { func (f *flowControlManager) StreamContributesToConnectionFlowControl(streamID protocol.StreamID) (bool, error) {
f.mutex.Lock() f.mutex.RLock()
defer f.mutex.Unlock() defer f.mutex.RUnlock()
contributes, ok := f.contributesToConnectionFlowControl[streamID] contributes, ok := f.contributesToConnectionFlowControl[streamID]
if !ok { if !ok {