Commit 1d220170 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/libwr: add function to force ignore WRS_SHM_LOCKED

It is necessary to ignore WRS_SHM_LOCKED, otherwise program opening the shmem
will wait for initial write.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 72b8cdfd
......@@ -44,6 +44,12 @@ struct wrs_shm_head {
/* Set custom path for shmem */
void wrs_shm_set_path(char *new_path);
/* Allow to ignore the flag WRS_SHM_LOCKED
* If this flag is not ignored then function wrs_shm_get_and_check is not able
* to open shmem successfully due to lack of process running with the given pid
*/
void wrs_shm_ignore_flag_locked(int ignore_flag);
/* get vs. put, like in the kernel. Errors are in errno (see source) */
void *wrs_shm_get(enum wrs_shm_name name_id, char *name, unsigned long flags);
int wrs_shm_put(void *headptr);
......
......@@ -16,6 +16,7 @@
#define SHM_LOCK_TIMEOUT_MS 50 /* in ms */
static char wrs_shm_path[50] = WRS_SHM_DEFAULT_PATH;
static int wrs_shm_locked = WRS_SHM_LOCKED;
/* Set custom path for shmem */
void wrs_shm_set_path(char *new_path)
......@@ -23,6 +24,18 @@ void wrs_shm_set_path(char *new_path)
strncpy(wrs_shm_path, new_path, 50);
}
/* Allow to ignore the flag WRS_SHM_LOCKED
* If this flag is not ignored then function wrs_shm_get_and_check is not able
* to open shmem successfully due to lack of process running with the given pid
*/
void wrs_shm_ignore_flag_locked(int ignore_flag)
{
if (ignore_flag)
wrs_shm_locked = 0;
else
wrs_shm_locked = WRS_SHM_LOCKED;
}
/* Get wrs shared memory */
/* return NULL and set errno on error */
void *wrs_shm_get(enum wrs_shm_name name_id, char *name, unsigned long flags)
......@@ -62,7 +75,7 @@ void *wrs_shm_get(enum wrs_shm_name name_id, char *name, unsigned long flags)
if (!write_access) {
/* This is a reader: if locked, wait for a writer */
if (!(flags & WRS_SHM_LOCKED))
if (!(flags & wrs_shm_locked))
return map;
tv1 = get_monotonic_tics();
......@@ -97,7 +110,7 @@ void *wrs_shm_get(enum wrs_shm_name name_id, char *name, unsigned long flags)
head->stamp = 0;
head->data_off = sizeof(*head);
head->data_size = 0;
if (flags & WRS_SHM_LOCKED)
if (flags & wrs_shm_locked)
head->sequence = 1; /* a sort of lock */
else
head->sequence = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment