Browse Source

Add helper functions to convert timespec to timeval and vice versa.

nfactor-troky
Con Kolivas 11 years ago
parent
commit
a6b1c31742
  1. 12
      util.c
  2. 2
      util.h

12
util.c

@ -890,6 +890,18 @@ void copy_time(struct timeval *dest, const struct timeval *src) @@ -890,6 +890,18 @@ void copy_time(struct timeval *dest, const struct timeval *src)
memcpy(dest, src, sizeof(struct timeval));
}
void timespec_to_val(struct timeval *val, const struct timespec *spec)
{
val->tv_sec = spec->tv_sec;
val->tv_usec = spec->tv_nsec / 1000;
}
void timeval_to_spec(struct timespec *spec, const struct timeval *val)
{
spec->tv_sec = val->tv_sec;
spec->tv_nsec = val->tv_usec * 1000;
}
/* Returns the microseconds difference between end and start times as a double */
double us_tdiff(struct timeval *end, struct timeval *start)
{

2
util.h

@ -78,6 +78,8 @@ void addtime(struct timeval *a, struct timeval *b); @@ -78,6 +78,8 @@ void addtime(struct timeval *a, struct timeval *b);
bool time_more(struct timeval *a, struct timeval *b);
bool time_less(struct timeval *a, struct timeval *b);
void copy_time(struct timeval *dest, const struct timeval *src);
void timespec_to_val(struct timeval *val, const struct timespec *spec);
void timeval_to_spec(struct timespec *spec, const struct timeval *val);
double us_tdiff(struct timeval *end, struct timeval *start);
double tdiff(struct timeval *end, struct timeval *start);
bool stratum_send(struct pool *pool, char *s, ssize_t len);

Loading…
Cancel
Save