apparently these features have been in Linux for a while now, so it makes sense to support them. the bit twiddling seems utterly illogical and wasteful, especially the negation, but that's how the kernel folks chose to encode pids/tids into the clock id.
15 lines
283 B
C
15 lines
283 B
C
#include <time.h>
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
#include "syscall.h"
|
|
|
|
int clock_getcpuclockid(pid_t pid, clockid_t *clk)
|
|
{
|
|
struct timespec ts;
|
|
clockid_t id = (-pid-1)*8U + 2;
|
|
int ret = __syscall(SYS_clock_getres, id, &ts);
|
|
if (ret) return -ret;
|
|
*clk = id;
|
|
return 0;
|
|
}
|