49#ifdef HAVE_GETTIMEOFDAY
55# include <sys/timeb.h>
67#ifdef CLOCKS_PER_SECOND
68#define CLOCKS_PER_SEC CLOCKS_PER_SECOND
70#define CLOCKS_PER_SEC 1000000
74#define N_USEC_PER_SEC 1000000L
95#ifdef HAVE_GETTIMEOFDAY
111 static bool first =
TRUE;
114 log_test(
"clock() returned -1, ignoring timer");
120#ifdef HAVE_GETTIMEOFDAY
125static void report_gettimeofday_failed(
struct timer *t)
127 static bool first =
TRUE;
130 log_test(
"gettimeofday() returned -1, ignoring timer");
135#elif !defined HAVE_FTIME
142 static bool first =
TRUE;
145 log_test(
"time() returned -1, ignoring timer");
232 log_error(
"tried to start already started timer");
236 t->start.c = clock();
237 if (
t->start.c == (clock_t) -1) {
242#ifdef HAVE_GETTIMEOFDAY
243 int ret = gettimeofday(&
t->start.tv, NULL);
246 report_gettimeofday_failed(
t);
249#elif defined HAVE_FTIME
252 t->start.t = time(NULL);
253 if (
t->start.t == (time_t) -1) {
276 log_error(
"tried to stop already stopped timer");
280 clock_t now = clock();
282 if (now == (clock_t) -1) {
289#ifdef HAVE_GETTIMEOFDAY
291 int ret = gettimeofday(&now, NULL);
294 report_gettimeofday_failed(t);
297 t->
usec += (now.tv_usec - t->
start.tv.tv_usec);
298 t->
sec += (now.tv_sec - t->
start.tv.tv_sec);
309#elif defined HAVE_FTIME
313 t->
usec += 1000 * ((long)now.millitm - (
long)t->
start.tp.millitm);
314 t->
sec += now.time - t->
start.tp.time;
326 time_t now = time(NULL);
328 if (now == (time_t) -1) {
366#ifdef HAVE_GETTIMEOFDAY
368 struct timeval tv_now;
374 ret = gettimeofday(&tv_now, NULL);
386 (tv_now.tv_usec - t->
start.tv.tv_usec);
387 wait_usec = usec - elapsed_usec;
393 long elapsed_usec, wait_usec;
398 + (now.millitm - t->
start.tp.millitm);
399 wait_usec = usec - elapsed_usec;
#define fc_assert_ret(condition)
#define fc_assert_ret_val(condition, val)
#define log_error(message,...)
void fc_usleep(unsigned long usec)
struct timer * timer_new(enum timer_timetype type, enum timer_use use)
static void report_time_failed(struct timer *t)
void timer_usleep_since_start(struct timer *t, long usec)
static void report_clock_failed(struct timer *t)
void timer_clear(struct timer *t)
bool timer_in_use(struct timer *t)
void timer_destroy(struct timer *t)
void timer_start(struct timer *t)
void timer_stop(struct timer *t)
double timer_read_seconds(struct timer *t)
struct timer * timer_renew(struct timer *t, enum timer_timetype type, enum timer_use use)