diff --git a/coio.c b/coio.c index 004ee58..d936e0c 100644 --- a/coio.c +++ b/coio.c @@ -19,6 +19,11 @@ #include "coioimpl.h" #include "coro.h" +#if defined(__APPLE__) +#include +#include +#endif + static coro_context _sched_ctx; static unsigned long _taskcount = 0; @@ -219,10 +224,21 @@ coio_transfer() uvlong coio_now() { +#if defined(__APPLE__) + clock_serv_t cclock; + mach_timespec_t mts; + + host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + + return (uvlong) mts.tv_sec * 1000 * 1000 * 1000 + mts.tv_nsec; +#else struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) return -1; return (uvlong) ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec; +#endif } diff --git a/coro.c b/coro.c index ff71383..d37b28d 100644 --- a/coro.c +++ b/coro.c @@ -123,7 +123,7 @@ trampoline (int sig) asm ( "\t.text\n" - #if _WIN32 || __CYGWIN__ + #if _WIN32 || __CYGWIN__ || __APPLE__ "\t.globl _coro_transfer\n" "_coro_transfer:\n" #else diff --git a/coro.h b/coro.h index 9f07c2d..3b08b81 100644 --- a/coro.h +++ b/coro.h @@ -303,7 +303,7 @@ void coro_stack_free (struct coro_stack *stack); # define CORO_ASM 1 # elif defined WINDOWS || defined _WIN32 # define CORO_LOSER 1 /* you don't win with windoze */ -# elif (__linux || __OpenBSD__) && (__i386 || (__x86_64 && !__ILP32)) +# elif (__linux || __OpenBSD__ || __APPLE__) && (__i386 || (__x86_64 && !__ILP32)) # define CORO_ASM 1 # elif defined HAVE_UCONTEXT_H # define CORO_UCONTEXT 1