Commit 656c6559 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/libwr: Print error message on multiple shmem locks

Print error message when shmem is locked or unlocked multiple times.
To be precise it will print error only on even locks or unlocks.

Move the increment of sequence before checking the flags to simplify further
if-conditions.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 2305ff10
......@@ -69,7 +69,11 @@ void *wrs_shm_follow(void *headptr, void *ptr);
/* Before and after writing a chunk of data, act on sequence and stamp */
#define WRS_SHM_WRITE_BEGIN 1
#define WRS_SHM_WRITE_END 0
extern void wrs_shm_write(void *headptr, int flags);
/* A helper to pass the name of caller function */
#define wrs_shm_write(headptr, flags) wrs_shm_write_caller(headptr, flags, \
__func__)
extern void wrs_shm_write_caller(void *headptr, int flags, const char *caller);
/* A reader can rely on the sequence number (in the <linux/seqlock.h> way) */
extern unsigned wrs_shm_seqbegin(void *headptr);
......
......@@ -12,6 +12,7 @@
#include <libwr/shmem.h>
#include <libwr/util.h>
#include <libwr/wrs-msg.h>
#define SHM_LOCK_TIMEOUT_MS 50 /* in ms */
......@@ -197,15 +198,29 @@ void *wrs_shm_follow(void *headptr, void *ptr)
}
/* Before and after writing a chunk of data, act on sequence and stamp */
void wrs_shm_write(void *headptr, int flags)
void wrs_shm_write_caller(void *headptr, int flags, const char *caller)
{
struct wrs_shm_head *head = headptr;
head->sequence++;
pr_debug("caller: %s\n", caller);
if (flags == WRS_SHM_WRITE_END) {
/* At end-of-writing update the timestamp too */
head->stamp = get_monotonic_sec();
if (head->sequence & 1)
pr_error("On the shmem write end the sequence number "
"(%d) is even (should be odd). The caller of"
" wrs_shm_write is %s\n",
head->sequence, caller);
} else {
if (!(head->sequence & 1))
pr_error("On the shmem write begin the sequence number"
" (%d) is odd (should be even). The caller of"
" wrs_shm_write is %s\n",
head->sequence, caller);
}
head->sequence++;
return;
}
......
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