don't defer unlocking the mutex when getting window updates

This commit is contained in:
Marten Seemann
2017-12-15 19:49:41 +07:00
parent efa781b067
commit 357a2f6213
2 changed files with 5 additions and 6 deletions

View File

@@ -54,13 +54,12 @@ func (c *connectionFlowController) IncrementHighestReceived(increment protocol.B
func (c *connectionFlowController) GetWindowUpdate() protocol.ByteCount {
c.mutex.Lock()
defer c.mutex.Unlock()
oldWindowIncrement := c.receiveWindowIncrement
offset := c.baseFlowController.getWindowUpdate()
if oldWindowIncrement < c.receiveWindowIncrement {
utils.Debugf("Increasing receive flow control window for the connection to %d kB", c.receiveWindowIncrement/(1<<10))
}
c.mutex.Unlock()
return offset
}
@@ -68,10 +67,9 @@ func (c *connectionFlowController) GetWindowUpdate() protocol.ByteCount {
// it should make sure that the connection-level window is increased when a stream-level window grows
func (c *connectionFlowController) EnsureMinimumWindowIncrement(inc protocol.ByteCount) {
c.mutex.Lock()
defer c.mutex.Unlock()
if inc > c.receiveWindowIncrement {
c.receiveWindowIncrement = utils.MinByteCount(inc, c.maxReceiveWindowIncrement)
c.lastWindowUpdateTime = time.Time{} // disables autotuning for the next window update
}
c.mutex.Unlock()
}

View File

@@ -113,11 +113,11 @@ func (c *streamFlowController) SendWindowSize() protocol.ByteCount {
}
func (c *streamFlowController) GetWindowUpdate() protocol.ByteCount {
// don't use defer for unlocking the mutex here, GetWindowUpdate() is called frequently and defer shows up in the profiler
c.mutex.Lock()
defer c.mutex.Unlock()
// if we already received the final offset for this stream, the peer won't need any additional flow control credit
if c.receivedFinalOffset {
c.mutex.Unlock()
return 0
}
@@ -129,5 +129,6 @@ func (c *streamFlowController) GetWindowUpdate() protocol.ByteCount {
c.connection.EnsureMinimumWindowIncrement(protocol.ByteCount(float64(c.receiveWindowIncrement) * protocol.ConnectionFlowControlMultiplier))
}
}
c.mutex.Unlock()
return offset
}