From e8695f1ee6058684668b629374f50c40462f017d Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 12 Jan 2021 14:57:24 +0000 Subject: [PATCH] Use RWMutex in notifier --- syncapi/notifier/notifier.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/syncapi/notifier/notifier.go b/syncapi/notifier/notifier.go index d853cc0e4..f5e4e3e61 100644 --- a/syncapi/notifier/notifier.go +++ b/syncapi/notifier/notifier.go @@ -36,7 +36,7 @@ type Notifier struct { // A map of RoomID => Set : Must only be accessed by the OnNewEvent goroutine roomIDToPeekingDevices map[string]peekingDeviceSet // Protects currPos and userStreams. - streamLock *sync.Mutex + streamLock *sync.RWMutex // The latest sync position currPos types.StreamingToken // A map of user_id => device_id => UserStream which can be used to wake a given user's /sync request. @@ -54,7 +54,7 @@ func NewNotifier(currPos types.StreamingToken) *Notifier { roomIDToJoinedUsers: make(map[string]userIDSet), roomIDToPeekingDevices: make(map[string]peekingDeviceSet), userDeviceStreams: make(map[string]map[string]*UserDeviceStream), - streamLock: &sync.Mutex{}, + streamLock: &sync.RWMutex{}, lastCleanUpTime: time.Now(), } } @@ -256,8 +256,8 @@ func (n *Notifier) Load(ctx context.Context, db storage.Database) error { // CurrentPosition returns the current sync position func (n *Notifier) CurrentPosition() types.StreamingToken { - n.streamLock.Lock() - defer n.streamLock.Unlock() + n.streamLock.RLock() + defer n.streamLock.RUnlock() return n.currPos }