summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
81d9c8b)
There is no need to actually obtain the lock. A single semaphore
operation will do just fine. With sem_op equal to zero and IPC_NOWAIT
the semop() call returns immediately, and the return value tells
whether the semaphore value was zero.
Rename the (static) function to mutex_is_locked() to indicate that
it performs only read-only operations on the semaphore set.
#include <stddef.h>
#include <limits.h>
#include <sys/param.h>
#include <stddef.h>
#include <limits.h>
#include <sys/param.h>
#include "gcc-compat.h"
#include "str.h"
#include "gcc-compat.h"
#include "str.h"
-static int mutex_try_lock(int id)
+static bool mutex_is_locked(int id)
int ret;
DSS_DEBUG_LOG(("trying to lock\n"));
int ret;
DSS_DEBUG_LOG(("trying to lock\n"));
- sops[0].sem_num = 0;
- sops[0].sem_op = 0;
- sops[0].sem_flg = SEM_UNDO | IPC_NOWAIT;
+ sops.sem_num = 0;
+ sops.sem_op = 0;
+ sops.sem_flg = SEM_UNDO | IPC_NOWAIT;
- sops[1].sem_num = 0;
- sops[1].sem_op = 1;
- sops[1].sem_flg = SEM_UNDO | IPC_NOWAIT;
-
- ret = do_semop(id, sops, 2);
+ ret = do_semop(id, &sops, 1);
- return -ERRNO_TO_DSS_ERROR(errno);
- return 1;
+ return true;
+ return false;
}
int lock_dss(char *config_file)
}
int lock_dss(char *config_file)
return -E_NOT_RUNNING;
if (pid)
*pid = ret;
return -E_NOT_RUNNING;
if (pid)
*pid = ret;
- ret = mutex_try_lock(semid);
- if (ret >= 0)
- return -E_NOT_RUNNING;
- return 1;
+ return mutex_is_locked(semid)? 1 : -E_NOT_RUNNING;