| 1 |
. |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#ifndef __TIME_SHIM_H |
| 9 |
#define __TIME_SHIM_H |
| 10 |
|
| 11 |
#include "config.h" |
| 12 |
|
| 13 |
#if defined(_WIN32) |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600 |
| 19 |
# undef _WIN32_WINNT |
| 20 |
# define _WIN32_WINNT 0x0600 |
| 21 |
#endif |
| 22 |
#include <winsock2.h> |
| 23 |
#include <time.h> |
| 24 |
#define usleep(a) Sleep((a)/1000) |
| 25 |
|
| 26 |
typedef struct timespec timespec_t; |
| 27 |
|
| 28 |
#if HAVE_CLOCK_GETTIME |
| 29 |
|
| 30 |
#define gettimeofday mingw_gettimeofday |
| 31 |
|
| 32 |
#else |
| 33 |
|
| 34 |
#ifndef CLOCK_REALTIME |
| 35 |
#define CLOCK_REALTIME 0 |
| 36 |
#endif |
| 37 |
|
| 38 |
#ifndef CLOCK_MONOTONIC |
| 39 |
#define CLOCK_MONOTONIC 1 |
| 40 |
#endif |
| 41 |
|
| 42 |
#ifndef CLOCK_PROCESS_CPUTIME_ID |
| 43 |
#define CLOCK_PROCESS_CPUTIME_ID 2 |
| 44 |
#endif |
| 45 |
|
| 46 |
#ifndef CLOCK_THREAD_CPUTIME_ID |
| 47 |
#define CLOCK_THREAD_CPUTIME_ID 3 |
| 48 |
#endif |
| 49 |
|
| 50 |
typedef int clockid_t; |
| 51 |
int gettimeofday(struct timeval *tv, void * not_implemented); |
| 52 |
int clock_gettime(clockid_t clock, timespec_t *tp); |
| 53 |
|
| 54 |
#endif |
| 55 |
#elif defined(__APPLE__) |
| 56 |
# define CLOCK_REALTIME_OSX 0 |
| 57 |
# define CLOCK_MONOTONIC_OSX 1 |
| 58 |
#if !HAVE_CLOCK_GETTIME |
| 59 |
typedef int clockid_t_osx; |
| 60 |
#else |
| 61 |
#ifndef CLOCK_REALTIME |
| 62 |
# define CLOCK_REALTIME CALENDAR_CLOCK |
| 63 |
# endif |
| 64 |
# ifndef CLOCK_MONOTONIC |
| 65 |
# define CLOCK_MONOTONIC SYSTEM_CLOCK |
| 66 |
# endif |
| 67 |
#endif |
| 68 |
#include <mach/mach_time.h> |
| 69 |
#include <time.h> |
| 70 |
typedef __darwin_time_t time_t; |
| 71 |
#ifndef _STRUCT_TIMESPEC |
| 72 |
struct timespec { |
| 73 |
time_t tv_sec; |
| 74 |
long tv_nsec; |
| 75 |
}; |
| 76 |
#endif |
| 77 |
typedef struct timespec timespec_t; |
| 78 |
#if HAVE_CLOCK_GETTIME |
| 79 |
int clock_gettime_osx(clock_id_t clock_id, timespec_t *tp); |
| 80 |
#else |
| 81 |
int clock_gettime_osx(clockid_t_osx clock_id, timespec_t *tp); |
| 82 |
#endif |
| 83 |
#else |
| 84 |
# include <sys/time.h> |
| 85 |
# include <time.h> |
| 86 |
typedef struct timespec timespec_t; |
| 87 |
#endif |
| 88 |
|
| 89 |
#endif |