github.com/containers/podman/v4@v4.9.4/libpod/lock/shm/shm_lock.h (about)

     1  #ifndef shm_locks_h_
     2  #define shm_locks_h_
     3  
     4  #include <pthread.h>
     5  #include <stdint.h>
     6  
     7  // Magic number to ensure we open the right SHM segment
     8  #define MAGIC 0x87D1
     9  
    10  // Type for our bitmaps
    11  typedef uint32_t bitmap_t;
    12  
    13  // bitmap size
    14  #define BITMAP_SIZE (sizeof(bitmap_t) * 8)
    15  
    16  // Struct to hold a single bitmap and associated locks
    17  typedef struct lock_group {
    18    bitmap_t        bitmap;
    19    pthread_mutex_t locks[BITMAP_SIZE];
    20  } lock_group_t;
    21  
    22  // Struct to hold our SHM locks.
    23  // Unused is required to be 0 in the current implementation. If we ever make
    24  // changes to this structure in the future, this will be repurposed as a version
    25  // field.
    26  typedef struct shm_struct {
    27    uint16_t        magic;
    28    uint16_t        unused;
    29    pthread_mutex_t segment_lock;
    30    uint32_t        num_bitmaps;
    31    uint32_t        num_locks;
    32    lock_group_t    locks[];
    33  } shm_struct_t;
    34  
    35  shm_struct_t *setup_lock_shm(char *path, uint32_t num_locks, int *error_code);
    36  shm_struct_t *open_lock_shm(char *path, uint32_t num_locks, int *error_code);
    37  int32_t close_lock_shm(shm_struct_t *shm);
    38  int64_t allocate_semaphore(shm_struct_t *shm);
    39  int32_t allocate_given_semaphore(shm_struct_t *shm, uint32_t sem_index);
    40  int32_t deallocate_semaphore(shm_struct_t *shm, uint32_t sem_index);
    41  int32_t deallocate_all_semaphores(shm_struct_t *shm);
    42  int32_t lock_semaphore(shm_struct_t *shm, uint32_t sem_index);
    43  int32_t unlock_semaphore(shm_struct_t *shm, uint32_t sem_index);
    44  int64_t available_locks(shm_struct_t *shm);
    45  int32_t try_lock(shm_struct_t *shm, uint32_t sem_index);
    46  
    47  #endif