From d34eabcd34b7f62e15db8d8929adbfc52806d5b3 Mon Sep 17 00:00:00 2001 From: Saxon Date: Wed, 17 Apr 2019 07:41:31 +0930 Subject: [PATCH] protocol/rtcp/client.go: not using defer for simple setters/getters --- protocol/rtcp/client.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/protocol/rtcp/client.go b/protocol/rtcp/client.go index 6e9fb750..796e4489 100644 --- a/protocol/rtcp/client.go +++ b/protocol/rtcp/client.go @@ -244,8 +244,9 @@ func (c *client) UpdateSequence(s uint32) { // highestSequence will return the highest sequence number received through RTP. func (c *client) highestSequence() uint32 { c.mu.Lock() - defer c.mu.Unlock() - return c.sequence + s := c.sequence + c.mu.Unlock() + return s } // jitter returns the interarrival jitter as described by RTCP specifications: @@ -257,30 +258,31 @@ func (c *client) jitter() uint32 { // setSenderTs allows us to safely set the current sender report timestamp. func (c *client) setSenderTs(msw, lsw uint32) { c.mu.Lock() - defer c.mu.Unlock() binary.BigEndian.PutUint32(c.senderTs[:], msw) binary.BigEndian.PutUint32(c.senderTs[4:], lsw) + c.mu.Unlock() } // lastSenderTs returns the timestamp of the most recent sender report. func (c *client) lastSenderTs() uint32 { c.mu.Lock() - defer c.mu.Unlock() - return binary.BigEndian.Uint32(c.senderTs[2:]) + t := binary.BigEndian.Uint32(c.senderTs[2:]) + c.mu.Unlock() + return t } // delay returns the duration between the receive time of the last sender report // and now. This is called when forming a receiver report. func (c *client) delay() uint32 { c.mu.Lock() - defer c.mu.Unlock() - now := time.Now() - return uint32(now.Sub(c.receiveTime).Seconds() / delayUnit) + t := c.receiveTime + c.mu.Unlock() + return uint32(time.Now().Sub(t).Seconds() / delayUnit) } // received is called when a sender report is received to mark the receive time. func (c *client) received() { c.mu.Lock() - defer c.mu.Unlock() c.receiveTime = time.Now() + c.mu.Unlock() }