aboutsummaryrefslogtreecommitdiffstats
path: root/src/zix/sem.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2014-09-28 17:34:07 +0000
committerDavid Robillard <d@drobilla.net>2014-09-28 17:34:07 +0000
commitfcb62b240e3f4b3a7257b6c1cd8e3b3a8cbd6d27 (patch)
treeb52ca39b387a6a0dc775d5751893a470c0aad943 /src/zix/sem.h
parentbc7e103c41031a57829ada9181af056fb9ffc8f7 (diff)
downloadjalv-fcb62b240e3f4b3a7257b6c1cd8e3b3a8cbd6d27.tar.gz
jalv-fcb62b240e3f4b3a7257b6c1cd8e3b3a8cbd6d27.tar.bz2
jalv-fcb62b240e3f4b3a7257b6c1cd8e3b3a8cbd6d27.zip
Update Zix stuff.
Turns out the previous fix was already implemented long ago, along with several others, and I need to remember to update things... git-svn-id: http://svn.drobilla.net/lad/trunk/jalv@5470 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/zix/sem.h')
-rw-r--r--src/zix/sem.h34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/zix/sem.h b/src/zix/sem.h
index 62f49f0..a7cb826 100644
--- a/src/zix/sem.h
+++ b/src/zix/sem.h
@@ -1,5 +1,5 @@
/*
- Copyright 2012 David Robillard <http://drobilla.net>
+ Copyright 2012-2014 David Robillard <http://drobilla.net>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -24,6 +24,7 @@
# include <windows.h>
#else
# include <semaphore.h>
+# include <errno.h>
#endif
#include "zix/common.h"
@@ -81,7 +82,7 @@ zix_sem_post(ZixSem* sem);
Wait until count is > 0, then decrement.
Obviously not realtime safe.
*/
-static inline void
+static inline ZixStatus
zix_sem_wait(ZixSem* sem);
/**
@@ -121,10 +122,13 @@ zix_sem_post(ZixSem* sem)
semaphore_signal(sem->sem);
}
-static inline void
+static inline ZixStatus
zix_sem_wait(ZixSem* sem)
{
- semaphore_wait(sem->sem);
+ if (semaphore_wait(sem->sem) != KERN_SUCCESS) {
+ return ZIX_STATUS_ERROR;
+ }
+ return ZIX_STATUS_SUCCESS;
}
static inline bool
@@ -159,10 +163,13 @@ zix_sem_post(ZixSem* sem)
ReleaseSemaphore(sem->sem, 1, NULL);
}
-static inline void
+static inline ZixStatus
zix_sem_wait(ZixSem* sem)
{
- WaitForSingleObject(sem->sem, INFINITE);
+ if (WaitForSingleObject(sem->sem, INFINITE) != WAIT_OBJECT_0) {
+ return ZIX_STATUS_ERROR;
+ }
+ return ZIX_STATUS_SUCCESS;
}
static inline bool
@@ -196,14 +203,17 @@ zix_sem_post(ZixSem* sem)
sem_post(&sem->sem);
}
-static inline void
+static inline ZixStatus
zix_sem_wait(ZixSem* sem)
{
- /* Note that sem_wait always returns 0 in practice, except in
- gdb (at least), where it returns nonzero, so the while is
- necessary (and is the correct/safe solution in any case).
- */
- while (sem_wait(&sem->sem) != 0) {}
+ while (sem_wait(&sem->sem)) {
+ if (errno != EINTR) {
+ return ZIX_STATUS_ERROR;
+ }
+ /* Otherwise, interrupted, so try again. */
+ }
+
+ return ZIX_STATUS_SUCCESS;
}
static inline bool