2020-06-15 07:18:57 -07:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_
|
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
2022-08-13 13:11:56 -07:00
|
|
|
COSMOPOLITAN_C_START_
|
2020-06-15 07:18:57 -07:00
|
|
|
|
|
|
|
struct timespec {
|
|
|
|
int64_t tv_sec;
|
|
|
|
int64_t tv_nsec; /* nanoseconds */
|
|
|
|
};
|
|
|
|
|
2024-01-09 01:26:03 -08:00
|
|
|
int clock_getres(int, struct timespec *) libcesque;
|
|
|
|
int clock_gettime(int, struct timespec *) libcesque;
|
|
|
|
int clock_settime(int, const struct timespec *) libcesque;
|
2022-10-05 06:37:15 -07:00
|
|
|
int clock_nanosleep(int, int, const struct timespec *, struct timespec *);
|
2024-01-09 01:26:03 -08:00
|
|
|
int futimens(int, const struct timespec[2]) libcesque;
|
|
|
|
int nanosleep(const struct timespec *, struct timespec *) libcesque;
|
|
|
|
int utimensat(int, const char *, const struct timespec[2], int) libcesque;
|
|
|
|
int timespec_getres(struct timespec *, int) libcesque;
|
|
|
|
int timespec_get(struct timespec *, int) libcesque;
|
2023-06-05 00:37:25 -07:00
|
|
|
|
2023-08-13 20:31:27 -07:00
|
|
|
#ifdef _COSMO_SOURCE
|
2024-02-24 10:00:44 -08:00
|
|
|
int sys_clock_nanosleep(int, int, const struct timespec *, struct timespec *);
|
2023-06-05 00:37:25 -07:00
|
|
|
#define timespec_zero ((struct timespec){0})
|
|
|
|
#define timespec_max ((struct timespec){0x7fffffffffffffff, 999999999})
|
2024-01-09 01:26:03 -08:00
|
|
|
libcesque int timespec_cmp(struct timespec, struct timespec) pureconst;
|
|
|
|
libcesque int64_t timespec_tomicros(struct timespec) pureconst;
|
|
|
|
libcesque int64_t timespec_tomillis(struct timespec) pureconst;
|
|
|
|
libcesque int64_t timespec_tonanos(struct timespec) pureconst;
|
|
|
|
libcesque struct timespec timespec_add(struct timespec,
|
|
|
|
struct timespec) pureconst;
|
|
|
|
libcesque struct timespec timespec_fromnanos(int64_t) pureconst;
|
|
|
|
libcesque struct timespec timespec_frommicros(int64_t) pureconst;
|
|
|
|
libcesque struct timespec timespec_frommillis(int64_t) pureconst;
|
|
|
|
libcesque struct timespec timespec_real(void) libcesque;
|
|
|
|
libcesque struct timespec timespec_mono(void) libcesque;
|
2024-09-04 00:38:44 -07:00
|
|
|
libcesque struct timespec timespec_sleep(int, struct timespec) libcesque;
|
|
|
|
libcesque int timespec_sleep_until(int, struct timespec) libcesque;
|
2024-01-09 01:26:03 -08:00
|
|
|
libcesque struct timespec timespec_sub(struct timespec,
|
|
|
|
struct timespec) pureconst;
|
|
|
|
libcesque struct timespec timespec_subz(struct timespec,
|
|
|
|
struct timespec) pureconst;
|
2023-06-09 18:02:06 -07:00
|
|
|
int sys_futex(int *, int, int, const struct timespec *, int *);
|
2023-08-07 20:22:49 -07:00
|
|
|
static inline struct timespec timespec_fromseconds(int64_t __x) {
|
|
|
|
return (struct timespec){__x};
|
|
|
|
}
|
2023-11-06 16:38:44 -08:00
|
|
|
static inline int timespec_iszero(struct timespec __ts) {
|
2023-06-15 13:50:42 -07:00
|
|
|
return !(__ts.tv_sec | __ts.tv_nsec);
|
|
|
|
}
|
2023-11-06 16:38:44 -08:00
|
|
|
static inline int timespec_isvalid(struct timespec __ts) {
|
2023-09-01 20:49:13 -07:00
|
|
|
return __ts.tv_sec >= 0 && __ts.tv_nsec + 0ull < 1000000000ull;
|
2023-06-15 13:50:42 -07:00
|
|
|
}
|
2023-08-13 20:31:27 -07:00
|
|
|
#endif /* _COSMO_SOURCE */
|
2022-06-08 20:01:28 -07:00
|
|
|
|
2022-08-13 13:11:56 -07:00
|
|
|
COSMOPOLITAN_C_END_
|
2020-06-15 07:18:57 -07:00
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_ */
|