1 #ifndef __TIMER_H 2 #define __TIMER_H 3 4 #include <time.h> 5 #include <sys/time.h> 6 7 struct timer { 8 struct timeval begin; 9 struct timeval end; 10 int (*expired)(struct timer *timer); 11 }; 12 13 struct timer *new_timer(time_t sec, suseconds_t usec); 14 15 int delay(int64_t ns); 16 17 double timeval_to_double(struct timeval *tv); 18 19 double timeval_diff(struct timeval *tv0, struct timeval *tv1); 20 21 int update_timer(struct timer *tp, time_t sec, suseconds_t usec); 22 23 int64_t timer_remaining(struct timer *tp); 24 25 void free_timer(struct timer *tp); 26 27 int timer_expired(struct timer *); 28 29 #endif 30