diff options
Diffstat (limited to 'pkg/mountmanager/keymutex.go')
| -rw-r--r-- | pkg/mountmanager/keymutex.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/pkg/mountmanager/keymutex.go b/pkg/mountmanager/keymutex.go new file mode 100644 index 0000000..0c64dcc --- /dev/null +++ b/pkg/mountmanager/keymutex.go @@ -0,0 +1,21 @@ +package mountmanager + +import "sync" + +// keyMutex provides a lock per key to serialize operations per volume. +type keyMutex struct { + mutexes sync.Map +} + +func newKeyMutex() *keyMutex { + return &keyMutex{} +} + +func (km *keyMutex) get(key string) *sync.Mutex { + m, _ := km.mutexes.LoadOrStore(key, &sync.Mutex{}) + return m.(*sync.Mutex) +} + +func (km *keyMutex) delete(key string) { + km.mutexes.Delete(key) +} |
