[chore] Tidy up federating db locks a tiny bit (#472)
This commit is contained in:
parent
0e2f31f4e3
commit
31c1067a54
|
@ -52,6 +52,7 @@ func (f *federatingDB) Lock(c context.Context, id *url.URL) error {
|
||||||
|
|
||||||
// Acquire map lock
|
// Acquire map lock
|
||||||
f.mutex.Lock()
|
f.mutex.Lock()
|
||||||
|
defer f.mutex.Unlock()
|
||||||
|
|
||||||
// Get mutex, or create new
|
// Get mutex, or create new
|
||||||
mu, ok := f.locks[idStr]
|
mu, ok := f.locks[idStr]
|
||||||
|
@ -63,8 +64,7 @@ func (f *federatingDB) Lock(c context.Context, id *url.URL) error {
|
||||||
f.locks[idStr] = mu
|
f.locks[idStr] = mu
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock map, acquire mutex lock
|
// Lock the mutex
|
||||||
f.mutex.Unlock()
|
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -81,13 +81,13 @@ func (f *federatingDB) Unlock(c context.Context, id *url.URL) error {
|
||||||
}
|
}
|
||||||
idStr := id.String()
|
idStr := id.String()
|
||||||
|
|
||||||
// Check map for mutex
|
// Acquire map lock
|
||||||
f.mutex.Lock()
|
f.mutex.Lock()
|
||||||
mu, ok := f.locks[idStr]
|
defer f.mutex.Unlock()
|
||||||
f.mutex.Unlock()
|
|
||||||
|
|
||||||
|
mu, ok := f.locks[idStr]
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("missing an id in unlock")
|
return errors.New("Unlock: missing an id in unlock")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock the mutex
|
// Unlock the mutex
|
||||||
|
|
Loading…
Reference in New Issue