diff options
Diffstat (limited to 'include/zix/sem.h')
-rw-r--r-- | include/zix/sem.h | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/include/zix/sem.h b/include/zix/sem.h index 8aa205e..49ab5f8 100644 --- a/include/zix/sem.h +++ b/include/zix/sem.h @@ -4,8 +4,8 @@ #ifndef ZIX_SEM_H #define ZIX_SEM_H -#include "zix/attributes.h" -#include "zix/status.h" +#include <zix/attributes.h> +#include <zix/status.h> #ifdef __APPLE__ # include <mach/mach.h> @@ -15,10 +15,10 @@ # include <semaphore.h> #endif -ZIX_BEGIN_DECLS - #include <stdint.h> +ZIX_BEGIN_DECLS + /** @defgroup zix_sem Semaphore @ingroup zix_threading @@ -30,14 +30,14 @@ ZIX_BEGIN_DECLS This is an integer that is never negative, and has two main operations: increment (post) and decrement (wait). If a decrement can't be performed - (because the value is 0) the caller will be blocked until another thread posts - and the operation can succeed. + (because the value is 0) the caller will be blocked until another thread + posts and the operation can succeed. Semaphores can be created with any starting value, but typically this will be 0 so the semaphore can be used as a simple signal where each post corresponds to one wait. - Semaphores are very efficient (much moreso than a mutex/cond pair). In + Semaphores are very efficient (compared to a mutex/cond pair). In particular, at least on Linux, post is async-signal-safe, which means it does not block and will not be interrupted. If you need to signal from a realtime thread, this is the most appropriate primitive to use. @@ -49,8 +49,7 @@ typedef struct ZixSemImpl ZixSem; @return #ZIX_STATUS_SUCCESS, or an unlikely error. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_sem_init(ZixSem* ZIX_NONNULL sem, unsigned initial); /** @@ -58,8 +57,7 @@ zix_sem_init(ZixSem* ZIX_NONNULL sem, unsigned initial); @return #ZIX_STATUS_SUCCESS, or an error. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_sem_destroy(ZixSem* ZIX_NONNULL sem); /** @@ -71,8 +69,7 @@ zix_sem_destroy(ZixSem* ZIX_NONNULL sem); if the maximum possible value would have been exceeded, or #ZIX_STATUS_BAD_ARG if `sem` is invalid. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_sem_post(ZixSem* ZIX_NONNULL sem); /** @@ -83,8 +80,7 @@ zix_sem_post(ZixSem* ZIX_NONNULL sem); @return #ZIX_STATUS_SUCCESS if `sem` was decremented, or #ZIX_STATUS_BAD_ARG if `sem` is invalid. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_sem_wait(ZixSem* ZIX_NONNULL sem); /** @@ -94,8 +90,7 @@ zix_sem_wait(ZixSem* ZIX_NONNULL sem); #ZIX_STATUS_UNAVAILABLE if it was already zero, or #ZIX_STATUS_BAD_ARG if `sem` is invalid. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_sem_try_wait(ZixSem* ZIX_NONNULL sem); /** @@ -108,8 +103,7 @@ zix_sem_try_wait(ZixSem* ZIX_NONNULL sem); the system does not support timed waits, or #ZIX_STATUS_BAD_ARG if `sem` is invalid. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_sem_timed_wait(ZixSem* ZIX_NONNULL sem, uint32_t seconds, uint32_t nanoseconds); |