tried a blindfix for unix + c11
This commit is contained in:
+3
-2
@@ -87,8 +87,8 @@ extern "C" {
|
|||||||
* The following list of build macros tries to "guess" if target OS is likely unix-like, and therefore can #include <unistd.h>
|
* The following list of build macros tries to "guess" if target OS is likely unix-like, and therefore can #include <unistd.h>
|
||||||
*/
|
*/
|
||||||
# elif !defined(_WIN32) \
|
# elif !defined(_WIN32) \
|
||||||
&& (defined(__unix__) || defined(__unix) \
|
&& ( defined(__unix__) || defined(__unix) \
|
||||||
|| defined(__midipix__) || defined(__VMS) || defined(__HAIKU__))
|
|| defined(__midipix__) || defined(__VMS) || defined(__HAIKU__) )
|
||||||
|
|
||||||
# if defined(__linux__) || defined(__linux)
|
# if defined(__linux__) || defined(__linux)
|
||||||
# ifndef _POSIX_C_SOURCE
|
# ifndef _POSIX_C_SOURCE
|
||||||
@@ -108,6 +108,7 @@ extern "C" {
|
|||||||
|
|
||||||
#endif /* PLATFORM_POSIX_VERSION */
|
#endif /* PLATFORM_POSIX_VERSION */
|
||||||
|
|
||||||
|
|
||||||
/*-*********************************************
|
/*-*********************************************
|
||||||
* Detect if isatty() and fileno() are available
|
* Detect if isatty() and fileno() are available
|
||||||
************************************************/
|
************************************************/
|
||||||
|
|||||||
+3
-6
@@ -72,11 +72,8 @@ PTime UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd)
|
|||||||
return ((clockEnd - clockStart) * (PTime)rate.numer) / ((PTime)rate.denom);
|
return ((clockEnd - clockStart) * (PTime)rate.numer) / ((PTime)rate.denom);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif (PLATFORM_POSIX_VERSION >= 200112L) \
|
#elif (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */) \
|
||||||
&& (defined(__UCLIBC__) \
|
&& defined (CLOCK_MONOTONIC)
|
||||||
|| (defined(__GLIBC__) \
|
|
||||||
&& ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17) \
|
|
||||||
|| (__GLIBC__ > 2))))
|
|
||||||
|
|
||||||
UTIL_time_t UTIL_getTime(void)
|
UTIL_time_t UTIL_getTime(void)
|
||||||
{
|
{
|
||||||
@@ -86,7 +83,7 @@ UTIL_time_t UTIL_getTime(void)
|
|||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
UTIL_time_t UTIL_getSpanTime(UTIL_time_t begin, UTIL_time_t end)
|
static UTIL_time_t UTIL_getSpanTime(UTIL_time_t begin, UTIL_time_t end)
|
||||||
{
|
{
|
||||||
UTIL_time_t diff;
|
UTIL_time_t diff;
|
||||||
if (end.tv_nsec < begin.tv_nsec) {
|
if (end.tv_nsec < begin.tv_nsec) {
|
||||||
|
|||||||
+10
-17
@@ -35,9 +35,9 @@ extern "C" {
|
|||||||
|
|
||||||
#if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
|
#if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
typedef uint64_t PTime; /* Precise Time */
|
typedef uint64_t PTime; /* Precise Time */
|
||||||
#else
|
#else
|
||||||
typedef unsigned long long PTime; /* does not support compilers without long long support */
|
typedef unsigned long long PTime; /* does not support compilers without long long support */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -47,42 +47,35 @@ extern "C" {
|
|||||||
******************************************/
|
******************************************/
|
||||||
#if defined(_WIN32) /* Windows */
|
#if defined(_WIN32) /* Windows */
|
||||||
|
|
||||||
#define UTIL_TIME_INITIALIZER { { 0, 0 } }
|
|
||||||
typedef LARGE_INTEGER UTIL_time_t;
|
typedef LARGE_INTEGER UTIL_time_t;
|
||||||
|
#define UTIL_TIME_INITIALIZER { { 0, 0 } }
|
||||||
|
|
||||||
#elif defined(__APPLE__) && defined(__MACH__)
|
#elif defined(__APPLE__) && defined(__MACH__)
|
||||||
|
|
||||||
#include <mach/mach_time.h>
|
#include <mach/mach_time.h>
|
||||||
#define UTIL_TIME_INITIALIZER 0
|
|
||||||
typedef PTime UTIL_time_t;
|
typedef PTime UTIL_time_t;
|
||||||
|
#define UTIL_TIME_INITIALIZER 0
|
||||||
|
|
||||||
#elif (PLATFORM_POSIX_VERSION >= 200112L) \
|
#elif (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */) \
|
||||||
&& (defined(__UCLIBC__) \
|
&& defined (CLOCK_MONOTONIC)
|
||||||
|| (defined(__GLIBC__) \
|
|
||||||
&& ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17) \
|
|
||||||
|| (__GLIBC__ > 2))))
|
|
||||||
|
|
||||||
|
typedef struct timespec UTIL_time_t; /* C11 defines struct timespes within time.h */
|
||||||
#define UTIL_TIME_INITIALIZER { 0, 0 }
|
#define UTIL_TIME_INITIALIZER { 0, 0 }
|
||||||
typedef struct timespec UTIL_freq_t;
|
|
||||||
typedef struct timespec UTIL_time_t;
|
|
||||||
|
|
||||||
UTIL_time_t UTIL_getSpanTime(UTIL_time_t begin, UTIL_time_t end);
|
#else /* relies on standard C90 (note : clock_t measurements can be wrong when using multi-threading) */
|
||||||
|
|
||||||
#else /* relies on standard C (note : clock_t measurements can be wrong when using multi-threading) */
|
|
||||||
|
|
||||||
typedef clock_t UTIL_time_t;
|
typedef clock_t UTIL_time_t;
|
||||||
#define UTIL_TIME_INITIALIZER 0
|
#define UTIL_TIME_INITIALIZER 0
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
UTIL_time_t UTIL_getTime(void);
|
UTIL_time_t UTIL_getTime(void);
|
||||||
PTime UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd);
|
PTime UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd);
|
||||||
PTime UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd);
|
PTime UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd);
|
||||||
|
|
||||||
|
#define SEC_TO_MICRO ((PTime)1000000)
|
||||||
#define SEC_TO_MICRO 1000000
|
|
||||||
PTime UTIL_clockSpanMicro(UTIL_time_t clockStart);
|
PTime UTIL_clockSpanMicro(UTIL_time_t clockStart);
|
||||||
|
|
||||||
PTime UTIL_clockSpanNano(UTIL_time_t clockStart);
|
PTime UTIL_clockSpanNano(UTIL_time_t clockStart);
|
||||||
|
|
||||||
void UTIL_waitForNextTick(void);
|
void UTIL_waitForNextTick(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user