implement OSX support

* clock_gettime alternative
* add OSX support to coro.c/.h
This commit is contained in:
Moritz Bitsch 2015-04-26 21:55:13 +02:00
parent 62979d013b
commit f4b1f3fae5
3 changed files with 18 additions and 2 deletions

16
coio.c
View file

@ -19,6 +19,11 @@
#include "coioimpl.h" #include "coioimpl.h"
#include "coro.h" #include "coro.h"
#if defined(__APPLE__)
#include <mach/clock.h>
#include <mach/mach.h>
#endif
static coro_context _sched_ctx; static coro_context _sched_ctx;
static unsigned long _taskcount = 0; static unsigned long _taskcount = 0;
@ -219,10 +224,21 @@ coio_transfer()
uvlong uvlong
coio_now() 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; struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
return -1; return -1;
return (uvlong) ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec; return (uvlong) ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
#endif
} }

2
coro.c
View file

@ -123,7 +123,7 @@ trampoline (int sig)
asm ( asm (
"\t.text\n" "\t.text\n"
#if _WIN32 || __CYGWIN__ #if _WIN32 || __CYGWIN__ || __APPLE__
"\t.globl _coro_transfer\n" "\t.globl _coro_transfer\n"
"_coro_transfer:\n" "_coro_transfer:\n"
#else #else

2
coro.h
View file

@ -303,7 +303,7 @@ void coro_stack_free (struct coro_stack *stack);
# define CORO_ASM 1 # define CORO_ASM 1
# elif defined WINDOWS || defined _WIN32 # elif defined WINDOWS || defined _WIN32
# define CORO_LOSER 1 /* you don't win with windoze */ # 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 # define CORO_ASM 1
# elif defined HAVE_UCONTEXT_H # elif defined HAVE_UCONTEXT_H
# define CORO_UCONTEXT 1 # define CORO_UCONTEXT 1