labcomm2006_compat_osx.h 601 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef __APPLE__
#error "__APPLE__" not defined
#endif

#ifndef LABCOMM_COMPAT_OSX
#define LABCOMM_COMPAT_OSX

#include <machine/endian.h>
#include <stdio.h>
#include <time.h>

#include <mach/clock.h>
#include <mach/mach.h>

#define CLOCK_REALTIME 0
static inline void clock_gettime(int garbage, struct timespec *ts)
{
  (void) garbage;
  clock_serv_t cclock;
  mach_timespec_t mts;
  host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
  clock_get_time(cclock, &mts);
  mach_port_deallocate(mach_task_self(), cclock);
  ts->tv_sec = mts.tv_sec;
  ts->tv_nsec = mts.tv_nsec;
}

#endif