diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-05-07 19:50:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-07 19:50:54 +0200 |
commit | 7b67c9601e1eab6c881ac44503c285c71b0a4a3a (patch) | |
tree | cf0802d1dee6beefd68e20b2a8345c9edeaec80f /libpod/lock/in_memory_locks.go | |
parent | 3b5ac1818f09514039fdfec20aa874ae68e6ab7c (diff) | |
parent | f881e32f12c9a30d903b15d8d51729b23928cfa3 (diff) | |
download | podman-7b67c9601e1eab6c881ac44503c285c71b0a4a3a.tar.gz podman-7b67c9601e1eab6c881ac44503c285c71b0a4a3a.tar.bz2 podman-7b67c9601e1eab6c881ac44503c285c71b0a4a3a.zip |
Merge pull request #3073 from mheon/force_lock_realloc
When refreshing after a reboot, force lock allocation
Diffstat (limited to 'libpod/lock/in_memory_locks.go')
-rw-r--r-- | libpod/lock/in_memory_locks.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libpod/lock/in_memory_locks.go b/libpod/lock/in_memory_locks.go index 7c9605917..f3c842f89 100644 --- a/libpod/lock/in_memory_locks.go +++ b/libpod/lock/in_memory_locks.go @@ -90,6 +90,22 @@ func (m *InMemoryManager) RetrieveLock(id uint32) (Locker, error) { return m.locks[id], nil } +// AllocateAndRetrieveLock allocates a lock with the given ID (if not already in +// use) and returns it. +func (m *InMemoryManager) AllocateAndRetrieveLock(id uint32) (Locker, error) { + if id >= m.numLocks { + return nil, errors.Errorf("given lock ID %d is too large - this manager only supports lock indexes up to %d", id, m.numLocks) + } + + if m.locks[id].allocated { + return nil, errors.Errorf("given lock ID %d is already in use, cannot reallocate", id) + } + + m.locks[id].allocated = true + + return m.locks[id], nil +} + // FreeAllLocks frees all locks. // This function is DANGEROUS. Please read the full comment in locks.go before // trying to use it. |