From 08b91b776d9bc9b99fa0dfcb4a771b99b74564fa Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Fri, 22 Apr 2016 16:21:27 +0000 Subject: [PATCH] Address feedback --- builtin/logical/transit/policy_crud.go | 2 +- builtin/logical/transit/simple_crud.go | 20 ++++++-------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/builtin/logical/transit/policy_crud.go b/builtin/logical/transit/policy_crud.go index 0a6b817b4..46472de96 100644 --- a/builtin/logical/transit/policy_crud.go +++ b/builtin/logical/transit/policy_crud.go @@ -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 diff --git a/builtin/logical/transit/simple_crud.go b/builtin/logical/transit/simple_crud.go index 8680a0cbe..6538c7eea 100644 --- a/builtin/logical/transit/simple_crud.go +++ b/builtin/logical/transit/simple_crud.go @@ -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