2019-04-10 19:37:03 +00:00
|
|
|
/*
|
2020-03-26 22:19:05 +00:00
|
|
|
* Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
|
2019-04-10 19:37:03 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under both the BSD-style license (found in the
|
|
|
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
|
|
* in the COPYING file in the root directory of this source tree).
|
|
|
|
* You may select, at your option, one of the above-listed licenses.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TIME_FN_H_MODULE_287987
|
|
|
|
#define TIME_FN_H_MODULE_287987
|
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*-****************************************
|
|
|
|
* Dependencies
|
|
|
|
******************************************/
|
|
|
|
#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-****************************************
|
|
|
|
* Local Types
|
|
|
|
******************************************/
|
|
|
|
|
|
|
|
#if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
|
|
|
|
# include <stdint.h>
|
2019-04-10 20:26:27 +00:00
|
|
|
typedef uint64_t PTime; /* Precise Time */
|
2019-04-10 19:37:03 +00:00
|
|
|
#else
|
2019-04-10 20:26:27 +00:00
|
|
|
typedef unsigned long long PTime; /* does not support compilers without long long support */
|
2019-04-10 19:37:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-****************************************
|
|
|
|
* Time functions
|
|
|
|
******************************************/
|
|
|
|
#if defined(_WIN32) /* Windows */
|
|
|
|
|
2019-11-12 23:59:06 +00:00
|
|
|
#include <windows.h> /* LARGE_INTEGER */
|
2019-04-10 19:37:03 +00:00
|
|
|
typedef LARGE_INTEGER UTIL_time_t;
|
2019-04-10 20:26:27 +00:00
|
|
|
#define UTIL_TIME_INITIALIZER { { 0, 0 } }
|
2019-04-10 19:37:03 +00:00
|
|
|
|
|
|
|
#elif defined(__APPLE__) && defined(__MACH__)
|
|
|
|
|
|
|
|
#include <mach/mach_time.h>
|
|
|
|
typedef PTime UTIL_time_t;
|
2019-04-10 20:26:27 +00:00
|
|
|
#define UTIL_TIME_INITIALIZER 0
|
2019-04-10 19:37:03 +00:00
|
|
|
|
2020-01-22 19:17:30 +00:00
|
|
|
/* C11 requires timespec_get, but FreeBSD 11 lacks it, while still claiming C11 compliance.
|
|
|
|
Android also lacks it but does define TIME_UTC. */
|
2019-04-10 22:22:18 +00:00
|
|
|
#elif (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */) \
|
2020-01-22 19:17:30 +00:00
|
|
|
&& defined(TIME_UTC) && !defined(__ANDROID__)
|
2019-04-10 19:37:03 +00:00
|
|
|
|
2019-04-10 22:22:18 +00:00
|
|
|
typedef struct timespec UTIL_time_t;
|
2019-04-10 19:37:03 +00:00
|
|
|
#define UTIL_TIME_INITIALIZER { 0, 0 }
|
|
|
|
|
2019-04-10 20:26:27 +00:00
|
|
|
#else /* relies on standard C90 (note : clock_t measurements can be wrong when using multi-threading) */
|
2019-04-10 19:37:03 +00:00
|
|
|
|
|
|
|
typedef clock_t UTIL_time_t;
|
|
|
|
#define UTIL_TIME_INITIALIZER 0
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-04-10 20:26:27 +00:00
|
|
|
|
2019-04-10 19:37:03 +00:00
|
|
|
UTIL_time_t UTIL_getTime(void);
|
|
|
|
PTime UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd);
|
|
|
|
PTime UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd);
|
|
|
|
|
2019-04-10 20:26:27 +00:00
|
|
|
#define SEC_TO_MICRO ((PTime)1000000)
|
2019-04-10 19:37:03 +00:00
|
|
|
PTime UTIL_clockSpanMicro(UTIL_time_t clockStart);
|
|
|
|
PTime UTIL_clockSpanNano(UTIL_time_t clockStart);
|
|
|
|
|
|
|
|
void UTIL_waitForNextTick(void);
|
|
|
|
|
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* TIME_FN_H_MODULE_287987 */
|