Path: blob/main/sys/contrib/zstd/programs/timefn.h
48254 views
/*1* Copyright (c) Yann Collet, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under both the BSD-style license (found in the5* LICENSE file in the root directory of this source tree) and the GPLv2 (found6* in the COPYING file in the root directory of this source tree).7* You may select, at your option, one of the above-listed licenses.8*/910#ifndef TIME_FN_H_MODULE_28798711#define TIME_FN_H_MODULE_2879871213#if defined (__cplusplus)14extern "C" {15#endif161718/*-****************************************19* Dependencies20******************************************/21#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */22232425/*-****************************************26* Local Types27******************************************/2829#if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )30# if defined(_AIX)31# include <inttypes.h>32# else33# include <stdint.h> /* intptr_t */34# endif35typedef uint64_t PTime; /* Precise Time */36#else37typedef unsigned long long PTime; /* does not support compilers without long long support */38#endif39404142/*-****************************************43* Time functions44******************************************/45#if defined(_WIN32) /* Windows */4647#include <windows.h> /* LARGE_INTEGER */48typedef LARGE_INTEGER UTIL_time_t;49#define UTIL_TIME_INITIALIZER { { 0, 0 } }5051#elif defined(__APPLE__) && defined(__MACH__)5253#include <mach/mach_time.h>54typedef PTime UTIL_time_t;55#define UTIL_TIME_INITIALIZER 05657/* C11 requires timespec_get, but FreeBSD 11 lacks it, while still claiming C11 compliance.58Android also lacks it but does define TIME_UTC. */59#elif (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */) \60&& defined(TIME_UTC) && !defined(__ANDROID__)6162typedef struct timespec UTIL_time_t;63#define UTIL_TIME_INITIALIZER { 0, 0 }6465#else /* relies on standard C90 (note : clock_t measurements can be wrong when using multi-threading) */6667typedef clock_t UTIL_time_t;68#define UTIL_TIME_INITIALIZER 06970#endif717273UTIL_time_t UTIL_getTime(void);74PTime UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd);75PTime UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd);7677#define SEC_TO_MICRO ((PTime)1000000)78PTime UTIL_clockSpanMicro(UTIL_time_t clockStart);79PTime UTIL_clockSpanNano(UTIL_time_t clockStart);8081void UTIL_waitForNextTick(void);828384#if defined (__cplusplus)85}86#endif8788#endif /* TIME_FN_H_MODULE_287987 */899091