aboutsummaryrefslogtreecommitdiff
path: root/libpod/lock/shm/shm_lock.h
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-08-10 13:46:07 -0400
committerMatthew Heon <matthew.heon@pm.me>2019-01-04 09:51:09 -0500
commite73484c176839b2f2adf3d07cc09222a7b75bf69 (patch)
treeca5226c7c3247901bb3732e207fdc929e3432343 /libpod/lock/shm/shm_lock.h
parentf38fccb48c9acc2b7d55c1746c9e6dbde492cff5 (diff)
downloadpodman-e73484c176839b2f2adf3d07cc09222a7b75bf69.tar.gz
podman-e73484c176839b2f2adf3d07cc09222a7b75bf69.tar.bz2
podman-e73484c176839b2f2adf3d07cc09222a7b75bf69.zip
Move to POSIX mutexes for SHM locks
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.h35
1 files changed, 19 insertions, 16 deletions
diff --git a/libpod/lock/shm/shm_lock.h b/libpod/lock/shm/shm_lock.h
index 18bea47e9..8e7e23fb7 100644
--- a/libpod/lock/shm/shm_lock.h
+++ b/libpod/lock/shm/shm_lock.h
@@ -1,14 +1,11 @@
#ifndef shm_locks_h_
#define shm_locks_h_
-#include <semaphore.h>
+#include <pthread.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"
+#define MAGIC 0x87D1
// Type for our bitmaps
typedef uint32_t bitmap_t;
@@ -18,22 +15,28 @@ typedef uint32_t bitmap_t;
// Struct to hold a single bitmap and associated locks
typedef struct lock_group {
- bitmap_t bitmap;
- sem_t locks[BITMAP_SIZE];
+ bitmap_t bitmap;
+ pthread_mutex_t locks[BITMAP_SIZE];
} lock_group_t;
-// Struct to hold our SHM locks
+// Struct to hold our SHM locks.
+// Unused is required to be 0 in the current implementation. If we ever make
+// changes to this structure in the future, this will be repurposed as a version
+// field.
typedef struct shm_struct {
- uint16_t magic;
- sem_t segment_lock;
- uint32_t num_bitmaps;
- uint32_t num_locks;
- lock_group_t locks[];
+ uint16_t magic;
+ uint16_t unused;
+ pthread_mutex_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);
+static size_t compute_shm_size(uint32_t num_bitmaps);
+static int take_mutex(pthread_mutex_t *mutex);
+static int release_mutex(pthread_mutex_t *mutex);
+shm_struct_t *setup_lock_shm(char *path, uint32_t num_locks, int *error_code);
+shm_struct_t *open_lock_shm(char *path, 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);