From d3ce713d9189bf96cfc05d729578d36214e8fe8d Mon Sep 17 00:00:00 2001 From: Radkesvat <134321679+radkesvat@users.noreply.github.com> Date: Mon, 10 Jun 2024 19:58:24 +0430 Subject: [PATCH] fixes around apple semaphore --- ww/eventloop/base/hmutex.h | 10 ++++++---- ww/eventloop/base/hthread.h | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ww/eventloop/base/hmutex.h b/ww/eventloop/base/hmutex.h index 722b1cb5..cfab73d9 100644 --- a/ww/eventloop/base/hmutex.h +++ b/ww/eventloop/base/hmutex.h @@ -191,8 +191,8 @@ static bool hsem_wait(hsem_t* sp) { } } -static bool hsem_post(hsem_t* sp, uint32_t count) { - assert(count > 0); +static bool hsem_post(hsem_t* sp) { + uint32_t count = 1; semaphore_t s = *(semaphore_t*)sp; kern_return_t rc = 0; // KERN_SUCCESS while (count-- > 0) { @@ -204,7 +204,8 @@ static bool hsem_post(hsem_t* sp, uint32_t count) { } return rc == KERN_SUCCESS; } - +#define USECS_IN_1_SEC 1000000 +#define NSECS_IN_1_SEC 1000000000 static bool hsem_wait_for(hsem_t* sp, uint64_t timeout_usecs) { mach_timespec_t ts; ts.tv_sec = (uint32_t)(timeout_usecs / USECS_IN_1_SEC); @@ -223,7 +224,8 @@ static bool hsem_wait_for(hsem_t* sp, uint64_t timeout_usecs) { return false; } } - +#undef USECS_IN_1_SEC +#undef NSECS_IN_1_SEC #else // linux semaphore diff --git a/ww/eventloop/base/hthread.h b/ww/eventloop/base/hthread.h index 489ae2bc..cad147bf 100644 --- a/ww/eventloop/base/hthread.h +++ b/ww/eventloop/base/hthread.h @@ -15,9 +15,9 @@ #define hv_gettid (long)gettid #elif defined(OS_LINUX) #include -#define hv_gettid() (long)syscall(SYS_gettid) +#define hv_gettid(void) (long)syscall(SYS_gettid) #elif defined(OS_DARWIN) -static inline long hv_gettid() { +static inline long hv_gettid(void) { uint64_t tid = 0; pthread_threadid_np(NULL, &tid); return tid;