1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| | #include <time.h>
#include "syscall.h"
#include "atomic.h"
static int syscall_clock_gettime(clockid_t clk, struct timespec *ts)
{
return __syscall(SYS_clock_gettime, clk, ts);
}
void *__vdsosym(const char *, const char *);
/* There is no other implemented value than TIME_UTC, all other values
are considered erroneous. */
int timespec_get(struct timespec * ts, int base)
{
if (base != TIME_UTC) return 0;
int ret;
#ifdef VDSO_CGT_SYM
static int (*cgt)(clockid_t, struct timespec *);
if (!cgt) {
void *f = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM);
if (!f) f = (void *)syscall_clock_gettime;
a_cas_p(&cgt, 0, f);
}
/* The vdso variants never fail, and thus never set errno. */
ret = cgt(CLOCK_REALTIME, ts);
#else
ret = syscall_clock_gettime(CLOCK_REALTIME, ts);
#endif
return ret < 0 ? 0 : base;
}
|