Commit 3fbbce3c authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(setup_timer): New function.

parent f80480bb
......@@ -26,7 +26,11 @@
# include <config.h>
#endif
#include <assert.h>
#include <sys/time.h>
#include <stdlib.h>
#include "oop.h"
#include "misc-types.h"
#include "timeval-util.h"
......@@ -139,3 +143,25 @@ timeval_diff_sec(struct timeval a, struct timeval b)
return res.tv_sec + (res.tv_usec >= 500000);
}
int
setup_timer(struct timeval *tv,
struct timeval interval)
{
if (gettimeofday(tv, NULL) < 0)
{
*tv = OOP_TIME_NOW;
return -1;
}
tv->tv_sec += interval.tv_sec;
tv->tv_usec += interval.tv_usec;
if (tv->tv_usec > 1000000)
{
tv->tv_usec -= 1000000;
tv->tv_sec++;
}
assert(tv->tv_usec >= 0);
assert(tv->tv_usec < 1000000);
return 0;
}
......@@ -41,3 +41,7 @@ extern Bool timeval_less(struct timeval a, struct timeval b);
/* Return the difference as a number of seconds, properly rounded. */
extern long timeval_diff_sec(struct timeval a, struct timeval b);
/* Set TV to the current time plus INTERVAL. Return -1 if
gettimeofday() fails (check errno). */
extern int setup_timer(struct timeval *tv, struct timeval interval);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment