Files
third_party_mesa3d/src/c11/impl/time.c
Yonggang Luo b2ddec4e98 c11: Implement c11/time.h with c11/impl/time.c
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>
2022-06-09 17:23:34 +00:00

44 lines
667 B
C

/*
* Copyright 2022 Yonggang Luo
* SPDX-License-Identifier: MIT
*
* C11 <time.h> implementation
*/
#include "c11/time.h"
#ifndef HAVE_TIMESPEC_GET
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <assert.h>
int
timespec_get(struct timespec *ts, int base)
{
assert(ts != NULL);
if (base == TIME_UTC) {
ts->tv_sec = time(NULL);
ts->tv_nsec = 0;
return base;
}
return 0;
}
#else
int
timespec_get(struct timespec *ts, int base)
{
if (!ts)
return 0;
if (base == TIME_UTC) {
clock_gettime(CLOCK_REALTIME, ts);
return base;
}
return 0;
}
#endif
#endif /* !HAVE_TIMESPEC_GET */