on cc8cd01 help sign in
36 lines 975 B history raw
1/*
2 * Code taken from the Haskell "clock" package.
3 *
4 * Copyright (c) 2009-2012, Cetin Sert
5 * Copyright (c) 2010, Eugene Kirpichov
6 *
7 * OS X code was contributed by Gerolf Seitz on 2013-10-15.
8 */
10#ifdef __MACH__
11#include <time.h>
12#include <mach/clock.h>
13#include <mach/mach.h>
15void clock_gettime_darwin(clock_id_t clock, struct timespec *ts)
17 clock_serv_t cclock;
18 mach_timespec_t mts;
19 host_get_clock_service(mach_host_self(), clock, &cclock);
20 clock_get_time(cclock, &mts);
21 mach_port_deallocate(mach_task_self(), cclock);
22 ts->tv_sec = mts.tv_sec;
23 ts->tv_nsec = mts.tv_nsec;
26void clock_getres_darwin(clock_id_t clock, struct timespec *ts)
28 clock_serv_t cclock;
29 int nsecs;
30 mach_msg_type_number_t count;
31 host_get_clock_service(mach_host_self(), clock, &cclock);
32 clock_get_attributes(cclock, CLOCK_GET_TIME_RES, (clock_attr_t)&nsecs, &count);
33 mach_port_deallocate(mach_task_self(), cclock);
36#endif /* __MACH__ */