mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-19 04:58:08 +02:00
Create c11/time.h instead of put timespec_get in `c11/threads.h` Creating impl folder is used to avoid `#include <time.h>` point the c11/time.h file Detecting if `struct timespec` present with meson Define TIME_UTC in `c11/time.h` instead `c11/threads.h` Define `struct timespec` in `c11/time.h` when not present. Implement timespec_get in c11/impl/time.c instead threads.h Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15497>
51 lines
1 KiB
C
51 lines
1 KiB
C
/*
|
|
* Copyright 2022 Yonggang Luo
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
* C11 <time.h> emulation library
|
|
*/
|
|
|
|
#ifndef C11_TIME_H_INCLUDED_
|
|
#define C11_TIME_H_INCLUDED_
|
|
|
|
#include <time.h>
|
|
|
|
/*---------------------------- macros ---------------------------*/
|
|
|
|
#ifndef TIME_UTC
|
|
#define TIME_UTC 1
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/*---------------------------- types ----------------------------*/
|
|
|
|
/*
|
|
* On MINGW `struct timespec` present but `timespec_get` may not present;
|
|
* On MSVC `struct timespec` and `timespec_get` present at the same time;
|
|
* So detecting `HAVE_STRUCT_TIMESPEC` in meson script dynamically.
|
|
*/
|
|
#ifndef HAVE_STRUCT_TIMESPEC
|
|
struct timespec
|
|
{
|
|
time_t tv_sec; // Seconds - >= 0
|
|
long tv_nsec; // Nanoseconds - [0, 999999999]
|
|
};
|
|
#endif
|
|
|
|
/*-------------------------- functions --------------------------*/
|
|
|
|
#ifndef HAVE_TIMESPEC_GET
|
|
/*-------------------- 7.25.7 Time functions --------------------*/
|
|
// 7.25.6.1
|
|
int
|
|
timespec_get(struct timespec *ts, int base);
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* C11_TIME_H_INCLUDED_ */
|