Skip to content

Commit

Permalink
fixes around apple semaphore
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Jun 10, 2024
1 parent a7d1208 commit d3ce713
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions ww/eventloop/base/hmutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions ww/eventloop/base/hthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#define hv_gettid (long)gettid
#elif defined(OS_LINUX)
#include <sys/syscall.h>
#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;
Expand Down

0 comments on commit d3ce713

Please sign in to comment.