1#pragma once
2/** Allows to build on MacOS X
3 *
4 * Highly experimental, not recommended, disabled by default.
5 *
6 * To use, include this file with -include compiler parameter.
7 */
8
9#include <time.h>
10
11#ifdef __APPLE__
12
13# if !defined(APPLE_HAVE_CLOCK_GETTIME)
14# include <AvailabilityMacros.h>
15# if !defined(MAC_OS_X_VERSION_10_12)
16# define MAC_OS_X_VERSION_10_12 101200
17# endif
18# define APPLE_HAVE_CLOCK_GETTIME MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
19# endif
20
21# if !APPLE_HAVE_CLOCK_GETTIME || !defined(CLOCK_MONOTONIC)
22/**
23 * MacOS X doesn't support different clock sources
24 *
25 * Mapping all of them to 0, except for
26 * CLOCK_THREAD_CPUTIME_ID, because there is a way
27 * to implement it using in-kernel stats about threads
28 */
29# if !defined(CLOCK_MONOTONIC)
30# define CLOCK_MONOTONIC 0
31# endif
32# if !defined(CLOCK_REALTIME)
33# define CLOCK_REALTIME CLOCK_MONOTONIC
34# endif
35# if !defined(CLOCK_THREAD_CPUTIME_ID)
36# define CLOCK_THREAD_CPUTIME_ID 3
37# endif
38
39typedef int clockid_t;
40int clock_gettime(int clk_id, struct timespec* t);
41# else
42
43# endif
44
45# if !defined(CLOCK_MONOTONIC_COARSE)
46# define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
47# endif
48
49#endif
50