6 timespec clock_diff(const timespec &a, const timespec &b)
9 ret.tv_sec = b.tv_sec - a.tv_sec;
10 ret.tv_nsec = b.tv_nsec - a.tv_nsec;
11 if (ret.tv_nsec < 0) {
13 ret.tv_nsec += 1000000000;
15 assert(ret.tv_nsec >= 0);
19 timespec clock_add(const timespec &a, const timespec &b)
22 ret.tv_sec = a.tv_sec + b.tv_sec;
23 ret.tv_nsec = b.tv_nsec + b.tv_nsec;
25 ret.tv_sec += ret.tv_nsec / 1000000000;
26 ret.tv_nsec %= 1000000000;