summaryrefslogtreecommitdiff
path: root/libpod/lock/shm/shm_lock.h
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-08-08 15:50:16 -0400
committerMatthew Heon <matthew.heon@pm.me>2019-01-04 09:45:59 -0500
commita21f21efa19372e055e8f1daf2e77c52e5352ccc (patch)
tree1cefa8e72f8d318ff47dd4925d486cd3081295d4 /libpod/lock/shm/shm_lock.h
parent3ed81051e814e688f7b4ae1bbc7c4d4c3fbd7d0f (diff)
downloadpodman-a21f21efa19372e055e8f1daf2e77c52e5352ccc.tar.gz
podman-a21f21efa19372e055e8f1daf2e77c52e5352ccc.tar.bz2
podman-a21f21efa19372e055e8f1daf2e77c52e5352ccc.zip
Refactor locks package to build on non-Linux
Move SHM specific code into a subpackage. Within the main locks package, move the manager to be linux-only and add a non-Linux unsupported build file. Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Diffstat (limited to 'libpod/lock/shm/shm_lock.h')
-rw-r--r--libpod/lock/shm/shm_lock.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/libpod/lock/shm/shm_lock.h b/libpod/lock/shm/shm_lock.h
new file mode 100644
index 000000000..18bea47e9
--- /dev/null
+++ b/libpod/lock/shm/shm_lock.h
@@ -0,0 +1,43 @@
+#ifndef shm_locks_h_
+#define shm_locks_h_
+
+#include <semaphore.h>
+#include <stdint.h>
+
+// Magic number to ensure we open the right SHM segment
+#define MAGIC 0xA5A5
+
+// Name of the SHM
+#define SHM_NAME "/libpod_lock"
+
+// Type for our bitmaps
+typedef uint32_t bitmap_t;
+
+// bitmap size
+#define BITMAP_SIZE (sizeof(bitmap_t) * 8)
+
+// Struct to hold a single bitmap and associated locks
+typedef struct lock_group {
+ bitmap_t bitmap;
+ sem_t locks[BITMAP_SIZE];
+} lock_group_t;
+
+// Struct to hold our SHM locks
+typedef struct shm_struct {
+ uint16_t magic;
+ sem_t segment_lock;
+ uint32_t num_bitmaps;
+ uint32_t num_locks;
+ lock_group_t locks[];
+} shm_struct_t;
+
+size_t compute_shm_size(uint32_t num_bitmaps);
+shm_struct_t *setup_lock_shm(uint32_t num_locks, int *error_code);
+shm_struct_t *open_lock_shm(uint32_t num_locks, int *error_code);
+int32_t close_lock_shm(shm_struct_t *shm);
+int64_t allocate_semaphore(shm_struct_t *shm);
+int32_t deallocate_semaphore(shm_struct_t *shm, uint32_t sem_index);
+int32_t lock_semaphore(shm_struct_t *shm, uint32_t sem_index);
+int32_t unlock_semaphore(shm_struct_t *shm, uint32_t sem_index);
+
+#endif