forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
posix_time.h
51 lines (39 loc) · 1.5 KB
/
posix_time.h
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once
#ifndef CATA_SRC_POSIX_TIME_H
#define CATA_SRC_POSIX_TIME_H
// Compatibility header. On POSIX, just include <ctime>. On Windows, provide
// our own nanosleep implementation.
#include <ctime> // IWYU pragma: keep
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(WINPTHREAD_API)
/* Windows platforms. */
/* Windows lacks the nanosleep() function. The following code was stuffed
together from GNUlib (http://www.gnu.org/software/gnulib/), which is
licensed under the GPLv3. */
enum { BILLION = 1000 * 1000 * 1000 };
# if defined(__cplusplus)
extern "C" {
# endif
// Apparently this is defined by pthread.h, if that header had been included.
// _INC_TIME is defined in time.h for MSVC
// __struct_timespec_defined is defined in time.h for MinGW on Windows
#if !defined(_TIMESPEC_DEFINED) && !defined(_INC_TIME) && !__struct_timespec_defined
#define _TIMESPEC_DEFINED
struct timespec {
time_t tv_sec;
long int tv_nsec;
};
#endif
# if defined(__cplusplus)
}
# endif
#include "platform_win.h"
/* The Win32 function Sleep() has a resolution of about 15 ms and takes
at least 5 ms to execute. We use this function for longer time periods.
Additionally, we use busy-looping over short time periods, to get a
resolution of about 0.01 ms. In order to measure such short time spans,
we use the QueryPerformanceCounter() function. */
int
nanosleep( const struct timespec *requested_delay,
struct timespec *remaining_delay );
#endif
#endif // CATA_SRC_POSIX_TIME_H