25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: timer.c,v 1.6 2006/12/30 13:30:53 debug Exp $ |
* $Id: timer.c,v 1.9 2007/06/15 17:02:38 debug Exp $ |
29 |
* |
* |
30 |
* Timer framework. This is used by emulated clocks. |
* Timer framework. This is used by emulated clocks. |
31 |
*/ |
*/ |
37 |
#include <unistd.h> |
#include <unistd.h> |
38 |
#include <sys/time.h> |
#include <sys/time.h> |
39 |
|
|
40 |
|
#include "misc.h" |
41 |
#include "timer.h" |
#include "timer.h" |
42 |
|
|
43 |
|
|
64 |
|
|
65 |
static int timer_is_running; |
static int timer_is_running; |
66 |
|
|
67 |
#define SECONDS_BETWEEN_GETTIMEOFDAY_SYNCH 1.5 |
#define SECONDS_BETWEEN_GETTIMEOFDAY_SYNCH 1.65 |
68 |
|
|
69 |
|
|
70 |
/* |
/* |
77 |
struct timer *timer_add(double freq, void (*timer_tick)(struct timer *timer, |
struct timer *timer_add(double freq, void (*timer_tick)(struct timer *timer, |
78 |
void *extra), void *extra) |
void *extra), void *extra) |
79 |
{ |
{ |
80 |
struct timer *newtimer = malloc(sizeof(struct timer)); |
struct timer *newtimer; |
81 |
if (newtimer == NULL) { |
|
82 |
fprintf(stderr, "out of memory\n"); |
CHECK_ALLOCATION(newtimer = malloc(sizeof(struct timer))); |
|
exit(1); |
|
|
} |
|
83 |
|
|
84 |
if (freq <= 0.00000001) |
if (freq <= 0.00000001) |
85 |
freq = 0.00000001; |
freq = 0.00000001; |
167 |
tv.tv_sec --; |
tv.tv_sec --; |
168 |
} |
} |
169 |
|
|
170 |
#if 0 |
#ifdef TIMER_DEBUG |
171 |
/* For debugging/testing: */ |
/* For debugging/testing: */ |
172 |
{ |
{ |
173 |
double diff = tv.tv_usec * 0.000001 + tv.tv_sec |
double diff = tv.tv_usec * 0.000001 + tv.tv_sec |
284 |
timer_is_running = 0; |
timer_is_running = 0; |
285 |
timer_countdown_to_next_gettimeofday = 0; |
timer_countdown_to_next_gettimeofday = 0; |
286 |
|
|
287 |
timer_freq = 50.0; |
timer_freq = TIMER_BASE_FREQUENCY; |
288 |
timer_current_time_step = 1.0 / timer_freq; |
timer_current_time_step = 1.0 / timer_freq; |
289 |
|
|
290 |
#ifdef TEST |
#ifdef TEST |