37 #if __STDC_VERSION__ >= 201112L
38 # define p00_has_feature_aligned_alloc 1
39 # define p00_has_extension_aligned_alloc 1
40 #elif (_XOPEN_SOURCE >= 600) || defined(P00_DOXYGEN)
42 # if !p99_has_feature(aligned_alloc)
44 # define p00_has_feature_aligned_alloc 1
45 # define p00_has_extension_aligned_alloc 1
55 int err = posix_memalign(&p00_ret, p00_alignment, p00_size);
71 # define p00_has_feature_quick_exit 1
72 # define p00_has_extension_quick_exit 1
74 #if __STDC_VERSION__ < 201112L
82 # if __GLIBC_PREREQ(2,13)
90 int at_quick_exit(
void (*p00_void_func)(
void)) {
114 void p00_run_at_thrd_exit(
void * li) {
119 # define P00_AT_THRD_EXIT P99_TSS_LOCAL(p00_at_thrd_exit)
142 int p00_timespec_get(
struct timespec *p00_ts,
int p00_base) {
144 if (gettimeofday(&t,
P99_0(
struct timezone*))) {
148 p00_ts->tv_sec = t.tv_sec;
151 p00_ts->tv_nsec = t.tv_usec;
153 p00_ts->tv_nsec *= 1000;
177 int timespec_get(
struct timespec *p00_ts,
int p00_base);
183 # ifdef CLOCK_PROCESS_CPUTIME_ID
184 p00_time_process_cputime_id,
186 # ifdef CLOCK_THREAD_CPUTIME_ID
187 p00_time_thread_cputime_id,
200 # define TIME_UTC p00_time_utc
202 # if defined(CLOCK_REALTIME) || defined(P00_DOXYGEN)
204 # if defined(CLOCK_MONOTONIC) || defined(P00_DOXYGEN)
218 # define TIME_MONOTONIC p00_time_monotonic
221 # ifdef CLOCK_PROCESS_CPUTIME_ID
222 # define TIME_PROCESS_CPUTIME_ID p00_time_process_cputime_id
224 # ifdef CLOCK_THREAD_CPUTIME_ID
225 # define TIME_THREAD_CPUTIME_ID p00_time_thread_cputime_id,
230 clockid_t p00_getclockid(
int base) {
231 return (base >= p00_time_base_max)
233 : (clockid_t
const[]) {
234 [p00_time_base] = CLOCK_REALTIME,
235 [p00_time_utc] = CLOCK_REALTIME,
236 # ifdef CLOCK_MONOTONIC
237 [p00_time_monotonic] = CLOCK_MONOTONIC,
239 # ifdef CLOCK_PROCESS_CPUTIME_ID
240 [p00_time_process_cputime_id] = CLOCK_PROCESS_CPUTIME_ID,
242 # ifdef CLOCK_THREAD_CPUTIME_ID
243 [p00_time_thread_cputime_id] = CLOCK_THREAD_CPUTIME_ID,
263 int timespec_get(
struct timespec *p00_ts,
int p00_base) {
264 clockid_t p00_clkid = p00_getclockid(p00_base);
265 if (clock_gettime(p00_clkid, p00_ts)) {
272 # elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
273 # include <mach/mach_time.h>
275 # define TIME_MONOTONIC p00_time_monotonic
281 struct timespec p00_timeoff_;
284 struct timespec const*
const p00_timeoff = &p00_timeoff_;
290 void p00_timeonce_init(
void) {
292 mach_timebase_info_data_t p00_tb =
P99_INIT;
293 mach_timebase_info(&p00_tb);
294 p00_timebase = p00_tb.numer;
295 p00_timebase /= p00_tb.denom;
298 uint64_t p00_nsec = mach_absolute_time() * p00_timebase;
299 p00_timespec_get(&p00_timeoff_,
TIME_UTC);
300 uint64_t
const p00_giga = UINT64_C(1000000000);
301 uint64_t p00_epoch = p00_timeoff_.tv_sec * p00_giga + p00_timeoff_.tv_nsec;
302 p00_epoch -= p00_nsec;
303 p00_timeoff_.tv_sec = p00_epoch / p00_giga;
304 p00_timeoff_.tv_nsec = p00_epoch % p00_giga;
308 int timespec_get(
struct timespec *p00_ts,
int p00_base) {
309 call_once(&p00_timeonce, p00_timeonce_init);
310 uint64_t p00_nsec = mach_absolute_time() * p00_timebase;
311 register uint64_t
const p00_giga = UINT64_C(1000000000);
312 p00_ts->tv_sec = p00_nsec / p00_giga;
313 p00_ts->tv_nsec = p00_nsec % p00_giga;
315 p00_ts->tv_sec += p00_timeoff->tv_sec;
316 p00_ts->tv_nsec += p00_timeoff->tv_nsec;
317 while (p00_ts->tv_nsec >= p00_giga) {
318 p00_ts->tv_nsec -= p00_giga;
325 # warning only low resolution gettimeofday found
326 # define timespec_get p00_timespec_get