From 0cffef37046bd5fc25f4584b402dee3f7d42b257 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 15 Apr 2015 05:36:46 +0200 Subject: reduce code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/cmdline.c | 67 ++++------------------------------------------------------- 1 file changed, 4 insertions(+), 63 deletions(-) (limited to 'src') 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 -- cgit v1.2.3-70-g09d2