aboutsummaryrefslogtreecommitdiffstats
path: root/common/threads.c
diff options
context:
space:
mode:
authoralexey.lysiuk <[email protected]>2018-10-15 16:40:57 +0000
committeralexey.lysiuk <[email protected]>2018-10-15 19:41:22 +0300
commitc8d866a25aa0499fa084074ebdc59c24ef9f2449 (patch)
tree07f99ceda1c72f7097023c0b3ed11e5596fbf824 /common/threads.c
parent6761218e51699f46bf25c377e65b3e9ea5e434b9 (diff)
Use GCD semaphore on macOS
Unnamed POSIX semaphore doesn't work on macOS
Diffstat (limited to 'common/threads.c')
-rw-r--r--common/threads.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/common/threads.c b/common/threads.c
index 6cfe383b..e8301297 100644
--- a/common/threads.c
+++ b/common/threads.c
@@ -631,6 +631,39 @@ void alcnd_destroy(alcnd_t *cond)
}
+#ifdef __APPLE__
+
+int alsem_init(alsem_t *sem, unsigned int initial)
+{
+ *sem = dispatch_semaphore_create(initial);
+ return *sem ? althrd_success : althrd_error;
+}
+
+void alsem_destroy(alsem_t *sem)
+{
+ dispatch_release(*sem);
+}
+
+int alsem_post(alsem_t *sem)
+{
+ dispatch_semaphore_signal(*sem);
+ return althrd_success;
+}
+
+int alsem_wait(alsem_t *sem)
+{
+ dispatch_semaphore_wait(*sem, DISPATCH_TIME_FOREVER);
+ return althrd_success;
+}
+
+int alsem_trywait(alsem_t *sem)
+{
+ long value = dispatch_semaphore_wait(*sem, DISPATCH_TIME_NOW);
+ return value == 0 ? althrd_success : althrd_busy;
+}
+
+#else /* !__APPLE__ */
+
int alsem_init(alsem_t *sem, unsigned int initial)
{
if(sem_init(sem, 0, initial) == 0)
@@ -665,6 +698,8 @@ int alsem_trywait(alsem_t *sem)
return althrd_error;
}
+#endif /* __APPLE__ */
+
int altss_create(altss_t *tss_id, altss_dtor_t callback)
{