Dynamic Load Balance 3.6.1+32-59d1
shmem.h
Go to the documentation of this file.
1/*********************************************************************************/
2/* Copyright 2009-2021 Barcelona Supercomputing Center */
3/* */
4/* This file is part of the DLB library. */
5/* */
6/* DLB is free software: you can redistribute it and/or modify */
7/* it under the terms of the GNU Lesser General Public License as published by */
8/* the Free Software Foundation, either version 3 of the License, or */
9/* (at your option) any later version. */
10/* */
11/* DLB is distributed in the hope that it will be useful, */
12/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14/* GNU Lesser General Public License for more details. */
15/* */
16/* You should have received a copy of the GNU Lesser General Public License */
17/* along with DLB. If not, see <https://www.gnu.org/licenses/>. */
18/*********************************************************************************/
19
20#ifndef SHMEM_H
21#define SHMEM_H
22
23#include <stdlib.h>
24#include <stdbool.h>
25#include <pthread.h>
26
27// Shared Memory State. Used for state-based locks.
28typedef enum ShmemState {
33
34// Shared Memory Sync. Must be a struct because it will be allocated inside the shmem
35typedef struct {
36 unsigned int shsync_version; // Shared Memory Sync version, set by the first process
37 unsigned int shmem_version; // Shared Memory version, set by the first process
38 int initializing; // Only the first process sets 0 -> 1
39 int initialized; // Only the first process sets 0 -> 1
40 shmem_state_t state; // Shared memory state
41 pthread_mutex_t shmem_mutex; // Mutex to grant exclusive access to the shmem
42 pid_t pidlist[]; // Array of attached PIDs
44
45enum { SHMEM_SYNC_VERSION = 3 };
46
47enum { SHM_NAME_LENGTH = 64 };
48
49typedef struct {
50 size_t shm_size;
51 char shm_filename[SHM_NAME_LENGTH];
52 char *shm_addr;
55
56typedef struct {
57 size_t size;
58 const char *name;
59 const char *key;
60 int color;
61 unsigned int version;
62 void (*cleanup_fn)(void*,int);
64
66
67shmem_handler_t* shmem_init(void **shdata, const shmem_props_t *shmem_props);
68void shmem_finalize(shmem_handler_t *handler, bool (*is_empty_fn)(void));
69void shmem_lock(shmem_handler_t *handler);
70void shmem_unlock(shmem_handler_t *handler);
73void shmem_acquire_busy( shmem_handler_t* handler );
74void shmem_release_busy( shmem_handler_t* handler );
75char *get_shm_filename(shmem_handler_t *handler);
76bool shmem_exists(const char *shmem_module, const char *shmem_key);
77void shmem_destroy(const char *shmem_module, const char *shmem_key);
78int shmem_shsync__version(void);
79size_t shmem_shsync__size(void);
80
81#endif /* SHMEM_H */
void shmem_acquire_busy(shmem_handler_t *handler)
Definition: shmem.c:319
void shmem_lock(shmem_handler_t *handler)
Definition: shmem.c:260
size_t shmem_shsync__size(void)
Definition: shmem.c:364
@ SHM_NAME_LENGTH
Definition: shmem.h:47
void shmem_release_busy(shmem_handler_t *handler)
Definition: shmem.c:330
@ SHMEM_VERSION_IGNORE
Definition: shmem.h:65
shmem_state_t
Definition: shmem.h:28
@ SHMEM_MAINTENANCE
Definition: shmem.h:31
@ SHMEM_BUSY
Definition: shmem.h:30
@ SHMEM_READY
Definition: shmem.h:29
bool shmem_exists(const char *shmem_module, const char *shmem_key)
Definition: shmem.c:340
void shmem_destroy(const char *shmem_module, const char *shmem_key)
Definition: shmem.c:350
shmem_handler_t * shmem_init(void **shdata, const shmem_props_t *shmem_props)
Definition: shmem.c:132
void shmem_lock_maintenance(shmem_handler_t *handler)
Definition: shmem.c:284
void shmem_unlock(shmem_handler_t *handler)
Definition: shmem.c:264
void shmem_finalize(shmem_handler_t *handler, bool(*is_empty_fn)(void))
Definition: shmem.c:227
@ SHMEM_SYNC_VERSION
Definition: shmem.h:45
char * get_shm_filename(shmem_handler_t *handler)
Definition: shmem.c:336
void shmem_unlock_maintenance(shmem_handler_t *handler)
Definition: shmem.c:308
int shmem_shsync__version(void)
Definition: shmem.c:360
Definition: comm_lend_light.c:32
Definition: shmem.h:49
char * shm_addr
Definition: shmem.h:52
size_t shm_size
Definition: shmem.h:50
shmem_sync_t * shsync
Definition: shmem.h:53
Definition: shmem.h:56
int color
Definition: shmem.h:60
unsigned int version
Definition: shmem.h:61
size_t size
Definition: shmem.h:57
const char * name
Definition: shmem.h:58
const char * key
Definition: shmem.h:59
Definition: shmem.h:35
unsigned int shmem_version
Definition: shmem.h:37
pthread_mutex_t shmem_mutex
Definition: shmem.h:41
shmem_state_t state
Definition: shmem.h:40
int initializing
Definition: shmem.h:38
int initialized
Definition: shmem.h:39
unsigned int shsync_version
Definition: shmem.h:36