From: Hallvard Furuseth Date: Fri, 5 Dec 2014 20:00:21 +0000 (+0100) Subject: C90-compatible code for SysV semaphores X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=03ddbcf37de9ebdf244d5be4d2213852b0fd6abb;p=openldap C90-compatible code for SysV semaphores --- diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index 1127dd0e3d..32e24c00f9 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -270,13 +270,18 @@ typedef struct mdb_mutex { #define MDB_MUTEX(env, rw) (&(env)->me_##rw##mutex) #define LOCK_MUTEX0(mutex) mdb_sem_wait(mutex) -#define UNLOCK_MUTEX(mutex) do { struct sembuf sb = { mutex->semnum, 1, SEM_UNDO }; semop(mutex->semid, &sb, 1); } while(0) +#define UNLOCK_MUTEX(mutex) do { \ + struct sembuf sb = { 0, 1, SEM_UNDO }; \ + sb.sem_num = (mutex)->semnum; \ + semop((mutex)->semid, &sb, 1); \ +} while(0) static int mdb_sem_wait(mdb_mutex_t *sem) { int rc; - struct sembuf sb = { sem->semnum, -1, SEM_UNDO }; + struct sembuf sb = { 0, -1, SEM_UNDO }; + sb.sem_num = sem->semnum; while ((rc = semop(sem->semid, &sb, 1)) && (rc = errno) == EINTR) ; return rc; } @@ -4417,6 +4422,11 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl) env->me_txns->mti_numreaders = 0; } else { +#ifdef MDB_USE_SYSV_SEM + struct semid_ds buf; + union semun semu; + int semid; +#endif if (env->me_txns->mti_magic != MDB_MAGIC) { DPUTS("lock region has invalid magic"); rc = MDB_INVALID; @@ -4438,9 +4448,7 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl) env->me_wmutex = OpenMutex(SYNCHRONIZE, FALSE, env->me_txns->mti_wmname); if (!env->me_wmutex) goto fail_errno; #elif defined(MDB_USE_SYSV_SEM) - struct semid_ds buf; - union semun semu; - int semid = env->me_txns->mti_semid; + semid = env->me_txns->mti_semid; semu.buf = &buf; /* check for read access */