Name the mutexes

This commit is contained in:
Mark Haines 2017-06-28 14:27:56 +01:00
parent 5f0bdd68be
commit 0ba35df6b8
3 changed files with 14 additions and 12 deletions

View file

@ -28,7 +28,7 @@ import (
// ensures that only one request is in flight to a given destination
// at a time.
type destinationQueue struct {
mutex sync.Mutex
runningMutex sync.Mutex
client *gomatrixserverlib.FederationClient
origin gomatrixserverlib.ServerName
destination gomatrixserverlib.ServerName
@ -42,10 +42,11 @@ type destinationQueue struct {
// If the queue is empty then it starts a background goroutine to
// start sending events to that destination.
func (oq *destinationQueue) sendEvent(ev *gomatrixserverlib.Event) {
oq.mutex.Lock()
defer oq.mutex.Unlock()
oq.runningMutex.Lock()
defer oq.runningMutex.Unlock()
oq.pendingEvents = append(oq.pendingEvents, ev)
if !oq.running {
oq.running = true
go oq.backgroundSend()
}
}
@ -76,8 +77,8 @@ func (oq *destinationQueue) backgroundSend() {
// and flushes the queue.
// Returns nil if the queue was empty.
func (oq *destinationQueue) next() *gomatrixserverlib.Transaction {
oq.mutex.Lock()
defer oq.mutex.Unlock()
oq.runningMutex.Lock()
defer oq.runningMutex.Unlock()
if len(oq.pendingEvents) == 0 {
oq.running = false
return nil

View file

@ -25,10 +25,10 @@ import (
// OutgoingQueues is a collection of queues for sending transactions to other
// matrix servers
type OutgoingQueues struct {
mutex sync.Mutex
queues map[gomatrixserverlib.ServerName]*destinationQueue
origin gomatrixserverlib.ServerName
client *gomatrixserverlib.FederationClient
origin gomatrixserverlib.ServerName
client *gomatrixserverlib.FederationClient
queuesMutex sync.Mutex
queues map[gomatrixserverlib.ServerName]*destinationQueue
}
// NewOutgoingQueues makes a new OutgoingQueues
@ -63,8 +63,8 @@ func (oqs *OutgoingQueues) SendEvent(
"destinations": destinations, "event": ev.EventID(),
}).Info("Sending event")
oqs.mutex.Lock()
defer oqs.mutex.Unlock()
oqs.queuesMutex.Lock()
defer oqs.queuesMutex.Unlock()
for _, destination := range destinations {
oq := oqs.queues[destination]
if oq == nil {

View file

@ -70,7 +70,8 @@ func (d *Database) SetPartitionOffset(topic string, partition int32, offset int6
return d.UpsertPartitionOffset(topic, partition, offset)
}
// UpdateRoom updates the joined hosts for a room.
// UpdateRoom updates the joined hosts for a room and returns what the joined
// hosts were before the update.
func (d *Database) UpdateRoom(
roomID, oldEventID, newEventID string,
addHosts []types.JoinedHost,