25 #ifdef HAVE_CLOCK_GETTIME
26 (void) clock_gettime(CLOCK_REALTIME, now);
29 (void) gettimeofday(&tv, NULL);
30 now->tv_sec = tv.tv_sec;
31 now->tv_nsec = tv.tv_usec * 1000;
37 struct timespec rqt, rmt;
39 for (rqt = *ts; nanosleep(&rqt, &rmt) < 0 && errno == EINTR; rqt = rmt)
45 b->tv_sec += a->tv_sec;
46 b->tv_nsec += a->tv_nsec;
47 while (b->tv_nsec >= NMSG_NSEC_PER_SEC) {
49 b->tv_nsec -= NMSG_NSEC_PER_SEC;
55 b->tv_sec -= a->tv_sec;
56 b->tv_nsec -= a->tv_nsec;
59 b->tv_nsec += NMSG_NSEC_PER_SEC;
65 return (ts->tv_sec + ts->tv_nsec / 1E9);
70 ts->tv_sec = (time_t) seconds;
71 ts->tv_nsec = (long) ((seconds - ((
int) seconds)) * 1E9);
void nmsg_timespec_get(struct timespec *ts)
Get the current time.
void nmsg_timespec_from_double(double seconds, struct timespec *ts)
Convert floating point number of seconds to timespec.
void nmsg_timespec_add(const struct timespec *a, struct timespec *b)
Add timespecs a and b, placing result in b.
double nmsg_timespec_to_double(const struct timespec *ts)
Convert timespec to floating point representation.
void nmsg_timespec_sleep(const struct timespec *ts)
Sleep.
void nmsg_timespec_sub(const struct timespec *a, struct timespec *b)
Subtract timespec b from a, placing result in b.