Address feedback
This commit is contained in:
parent
6f7409bb49
commit
08b91b776d
|
@ -42,7 +42,7 @@ type policyCRUD interface {
|
|||
}
|
||||
|
||||
// The mutex is kept separate from the struct since we may set it to its own
|
||||
// mutex (if the object is shared) or a shared mutext (if the object isn't
|
||||
// mutex (if the object is shared) or a shared mutex (if the object isn't
|
||||
// shared and only the locking is)
|
||||
type mutexLockingPolicy struct {
|
||||
mutex *sync.RWMutex
|
||||
|
|
|
@ -11,8 +11,7 @@ import (
|
|||
// backend from multiple operators
|
||||
type simplePolicyCRUD struct {
|
||||
sync.RWMutex
|
||||
locks map[string]*sync.RWMutex
|
||||
locksMapMutex sync.RWMutex
|
||||
locks map[string]*sync.RWMutex
|
||||
}
|
||||
|
||||
func newSimplePolicyCRUD() *simplePolicyCRUD {
|
||||
|
@ -21,21 +20,14 @@ func newSimplePolicyCRUD() *simplePolicyCRUD {
|
|||
}
|
||||
}
|
||||
|
||||
// The write lock must be held before calling this; for this CRUD type this
|
||||
// should always be the case, since the only method not requiring a write lock
|
||||
// when called is getPolicy, and that itself grabs a write lock before calling
|
||||
// refreshPolicy
|
||||
func (p *simplePolicyCRUD) ensureLockExists(name string) {
|
||||
p.locksMapMutex.RLock()
|
||||
|
||||
if p.locks[name] == nil {
|
||||
p.locksMapMutex.RUnlock()
|
||||
p.locksMapMutex.Lock()
|
||||
// Make sure nothing has appeared since we switched the lock type
|
||||
if p.locks[name] == nil {
|
||||
p.locks[name] = &sync.RWMutex{}
|
||||
}
|
||||
p.locksMapMutex.Unlock()
|
||||
return
|
||||
p.locks[name] = &sync.RWMutex{}
|
||||
}
|
||||
|
||||
p.locksMapMutex.RUnlock()
|
||||
}
|
||||
|
||||
// See general comments on the interface method
|
||||
|
|
Loading…
Reference in a new issue