summaryrefslogtreecommitdiff
path: root/internal/federation/federatingdb/lock.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-04-19 16:31:37 +0200
committerLibravatar GitHub <noreply@github.com>2022-04-19 16:31:37 +0200
commit31c1067a548039e7d95f131b3972ecfe1f57f835 (patch)
tree3ee9a160695a5cd3c2eecee84f7975de98729a5a /internal/federation/federatingdb/lock.go
parent[Documentation] Simplify docker-compose documentation + example (#468) (diff)
downloadgotosocial-31c1067a548039e7d95f131b3972ecfe1f57f835.tar.xz
[chore] Tidy up federating db locks a tiny bit (#472)
Diffstat (limited to 'internal/federation/federatingdb/lock.go')
-rw-r--r--internal/federation/federatingdb/lock.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/internal/federation/federatingdb/lock.go b/internal/federation/federatingdb/lock.go
index 22f2bb77a..4609cd99e 100644
--- a/internal/federation/federatingdb/lock.go
+++ b/internal/federation/federatingdb/lock.go
@@ -52,6 +52,7 @@ func (f *federatingDB) Lock(c context.Context, id *url.URL) error {
// Acquire map lock
f.mutex.Lock()
+ defer f.mutex.Unlock()
// Get mutex, or create new
mu, ok := f.locks[idStr]
@@ -63,8 +64,7 @@ func (f *federatingDB) Lock(c context.Context, id *url.URL) error {
f.locks[idStr] = mu
}
- // Unlock map, acquire mutex lock
- f.mutex.Unlock()
+ // Lock the mutex
mu.Lock()
return nil
}
@@ -81,13 +81,13 @@ func (f *federatingDB) Unlock(c context.Context, id *url.URL) error {
}
idStr := id.String()
- // Check map for mutex
+ // Acquire map lock
f.mutex.Lock()
- mu, ok := f.locks[idStr]
- f.mutex.Unlock()
+ defer f.mutex.Unlock()
+ mu, ok := f.locks[idStr]
if !ok {
- return errors.New("missing an id in unlock")
+ return errors.New("Unlock: missing an id in unlock")
}
// Unlock the mutex