add per-room mutex, possibly fixes #8

This commit is contained in:
Aine
2022-08-27 22:10:22 +03:00
parent 9484758f33
commit d1c48b9b31
4 changed files with 38 additions and 0 deletions

26
bot/mutext.go Normal file
View File

@@ -0,0 +1,26 @@
package bot
import (
"sync"
"maunium.net/go/mautrix/id"
)
func (b *Bot) lock(roomID id.RoomID) {
_, ok := b.mu[roomID]
if !ok {
b.mu[roomID] = &sync.Mutex{}
}
b.mu[roomID].Lock()
}
func (b *Bot) unlock(roomID id.RoomID) {
_, ok := b.mu[roomID]
if !ok {
return
}
b.mu[roomID].Unlock()
delete(b.mu, roomID)
}