aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmdline.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-04-15 05:36:46 +0200
committerMattias Andrée <maandree@operamail.com>2015-04-15 05:36:46 +0200
commit0cffef37046bd5fc25f4584b402dee3f7d42b257 (patch)
tree1904a3df753c37827d7543227d34ca70d0199767 /src/cmdline.c
parentthird draft (diff)
downloadbus-0cffef37046bd5fc25f4584b402dee3f7d42b257.tar.gz
bus-0cffef37046bd5fc25f4584b402dee3f7d42b257.tar.bz2
bus-0cffef37046bd5fc25f4584b402dee3f7d42b257.tar.xz
reduce code
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/cmdline.c67
1 files changed, 4 insertions, 63 deletions
diff --git a/src/cmdline.c b/src/cmdline.c
index a86b81b..a1ebafe 100644
--- a/src/cmdline.c
+++ b/src/cmdline.c
@@ -143,25 +143,7 @@ remove_shared_memory(key_t key)
static int
-acquire_semaphore(key_t key, int semaphore, int delta, int undo)
-{
- struct sembuf op;
- int id;
-
- id = semget(key, SEMAPHORES, 0600);
- if (id == -1)
- return -1;
-
- op.sem_op = -delta;
- op.sem_num = semaphore;
- op.sem_flg = undo * SEM_UNDO;
-
- return semop(id, &op, 1);
-}
-
-
-static int
-release_semaphore(key_t key, int semaphore, int delta, int undo)
+semaphore_op(key_t key, int semaphore, int delta, int undo)
{
struct sembuf op;
int id;
@@ -178,50 +160,9 @@ release_semaphore(key_t key, int semaphore, int delta, int undo)
}
-static int
-zero_semaphore(key_t key, int semaphore)
-{
- struct sembuf op;
- int id;
-
- id = semget(key, SEMAPHORES, 0600);
- if (id == -1)
- return -1;
-
- op.sem_op = 0;
- op.sem_num = semaphore;
- op.sem_flg = 0;
-
- return semop(id, &op, 1);
-}
-
-
-static int
-read_semaphore(key_t key, int semaphore, int *z, int *n, int *v)
-{
- int id, r;
-
- id = semget(key, SEMAPHORES, 0600);
- if (id == -1)
- return -1;
-
- if (r = semctl(id, semaphore, GETZCNT), r == -1)
- return -1;
- if (z)
- *z = r;
-
- if (r = semctl(id, semaphore, GETNCNT), r == -1)
- return -1;
- if (n)
- *n = r;
-
- if (r = semctl(id, semaphore, GETVAL), r == -1)
- return -1;
- if (v)
- *v = r;
-
- return 0;
-}
+#define acquire_semaphore(key, semaphore, delta, undo) semaphore_op(key, semaphore, -delta, undo)
+#define release_semaphore(key, semaphore, delta, undo) semaphore_op(key, semaphore, +delta, undo)
+#define zero_semaphore(key, semaphore) semaphore_op(key, semaphore, 0, 0)
static int