diff options
author | Yonggang Luo <luoyonggang@gmail.com> | 2022-02-19 13:19:08 +0800 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2022-06-09 17:23:34 +0000 |
commit | b2ddec4e98fea9b824e7258468e5b5da9ba848b0 (patch) | |
tree | 0f86a76ffc46f5a9a31a55e9db423f48c3358381 /include | |
parent | fe01757ddf067414646032f5fd7ffc5a4d332591 (diff) | |
download | mesa-b2ddec4e98fea9b824e7258468e5b5da9ba848b0.tar.gz mesa-b2ddec4e98fea9b824e7258468e5b5da9ba848b0.tar.bz2 mesa-b2ddec4e98fea9b824e7258468e5b5da9ba848b0.zip |
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>
Diffstat (limited to 'include')
-rw-r--r-- | include/c11/threads.h | 6 | ||||
-rw-r--r-- | include/c11/threads_posix.h | 16 | ||||
-rw-r--r-- | include/c11/threads_win32.h | 27 |
3 files changed, 1 insertions, 48 deletions
diff --git a/include/c11/threads.h b/include/c11/threads.h index 81f4b9b7c09..75bd445faff 100644 --- a/include/c11/threads.h +++ b/include/c11/threads.h @@ -29,11 +29,7 @@ #ifndef EMULATED_THREADS_H_INCLUDED_ #define EMULATED_THREADS_H_INCLUDED_ -#include <time.h> - -#ifndef TIME_UTC -#define TIME_UTC 1 -#endif +#include "c11/time.h" /*---------------------------- types ----------------------------*/ typedef void (*tss_dtor_t)(void*); diff --git a/include/c11/threads_posix.h b/include/c11/threads_posix.h index 802526a77c8..8e17686d51a 100644 --- a/include/c11/threads_posix.h +++ b/include/c11/threads_posix.h @@ -378,19 +378,3 @@ tss_set(tss_t key, void *val) { return (pthread_setspecific(key, val) == 0) ? thrd_success : thrd_error; } - - -/*-------------------- 7.25.7 Time functions --------------------*/ -// 7.25.6.1 -#ifndef HAVE_TIMESPEC_GET -static inline 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 diff --git a/include/c11/threads_win32.h b/include/c11/threads_win32.h index 13feb820d07..dbda982f7d5 100644 --- a/include/c11/threads_win32.h +++ b/include/c11/threads_win32.h @@ -128,7 +128,6 @@ static time_t impl_timespec2msec(const struct timespec *ts) return (ts->tv_sec * 1000U) + (ts->tv_nsec / 1000000L); } -#ifdef HAVE_TIMESPEC_GET static DWORD impl_abs2relmsec(const struct timespec *abs_time) { const time_t abs_ms = impl_timespec2msec(abs_time); @@ -138,7 +137,6 @@ static DWORD impl_abs2relmsec(const struct timespec *abs_time) const DWORD rel_ms = (abs_ms > now_ms) ? (DWORD)(abs_ms - now_ms) : 0; return rel_ms; } -#endif #ifdef EMULATED_THREADS_USE_NATIVE_CALL_ONCE struct impl_call_once_param { void (*func)(void); }; @@ -253,14 +251,10 @@ cnd_timedwait(cnd_t *cond, mtx_t *mtx, const struct timespec *abs_time) assert(cond != NULL); assert(mtx != NULL); assert(abs_time != NULL); -#ifdef HAVE_TIMESPEC_GET const DWORD timeout = impl_abs2relmsec(abs_time); if (SleepConditionVariableCS(cond, mtx, timeout)) return thrd_success; return (GetLastError() == ERROR_TIMEOUT) ? thrd_timedout : thrd_error; -#else - return thrd_error; -#endif } // 7.25.3.6 @@ -312,7 +306,6 @@ mtx_timedlock(mtx_t *mtx, const struct timespec *ts) { assert(mtx != NULL); assert(ts != NULL); -#ifdef HAVE_TIMESPEC_GET while (mtx_trylock(mtx) != thrd_success) { if (impl_abs2relmsec(ts) == 0) return thrd_timedout; @@ -320,9 +313,6 @@ mtx_timedlock(mtx_t *mtx, const struct timespec *ts) thrd_yield(); } return thrd_success; -#else - return thrd_error; -#endif } // 7.25.4.5 @@ -502,20 +492,3 @@ tss_set(tss_t key, void *val) { return TlsSetValue(key, val) ? thrd_success : thrd_error; } - - -/*-------------------- 7.25.7 Time functions --------------------*/ -// 7.25.6.1 -#ifndef HAVE_TIMESPEC_GET -static inline 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; -} -#endif |