From b0b0e48409df359f3be15ba112a89365b10ecd67 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Fri, 22 May 2020 05:07:19 +0200 Subject: [PATCH] macos: Use for locking the global compiler lock can't be a POSIX non-shared semaphore on Darwin (because not implemented there). Use the dispatch framework. --- libtcc.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libtcc.c b/libtcc.c index 81c65444..256dfb68 100644 --- a/libtcc.c +++ b/libtcc.c @@ -129,6 +129,20 @@ static void wait_sem(void) } #define WAIT_SEM() wait_sem() #define POST_SEM() LeaveCriticalSection(&tcc_cr); +#elif defined __APPLE__ +/* Half-compatible MacOS doesn't have non-shared (process local) + semaphores. Use the dispatch framework for lightweight locks. */ +#include +static int tcc_sem_init; +static dispatch_semaphore_t tcc_sem; +static void wait_sem(void) +{ + if (!tcc_sem_init) + tcc_sem = dispatch_semaphore_create(1), tcc_sem_init = 1; + dispatch_semaphore_wait(tcc_sem, DISPATCH_TIME_FOREVER); +} +#define WAIT_SEM() wait_sem() +#define POST_SEM() dispatch_semaphore_signal(tcc_sem) #else #include static int tcc_sem_init;