3 * helpers for event handling
11 const char toev_fast_pclass[]= "fast";
13 void real_mgettimeofday(struct timeval *tv) {
15 r= gettimeofday(tv,0);
16 if (r) diee("gettimeofday failed");
19 static int toev_sim_show(TimeoutEvent *toev) {
20 return simlog_full || toev->pclass!=toev_fast_pclass;
23 void *toev_callback(oop_source *source, struct timeval tv, void *t_v) {
24 TimeoutEvent *toev= t_v;
25 if (toev_sim_show(toev)) {
26 simlog("timer-event %s.%s\n",toev->pclass,toev->pinst);
34 void toev_init(TimeoutEvent *toev) { toev->running= 0; }
36 void toev_start(TimeoutEvent *toev) {
38 if (toev->duration==-1) return;
40 if (toev_sim_show(toev)) mgettimeofday(&toev->abs);
41 else real_mgettimeofday(&toev->abs);
42 assert(toev->duration < INT_MAX/1000);
43 toev->abs.tv_usec += toev->duration * 1000;
44 toev->abs.tv_sec += toev->abs.tv_usec / 1000000;
45 toev->abs.tv_usec %= 1000000;
46 if (simulate) sim_toev_start(toev);
47 else events->on_time(events, toev->abs, toev_callback, toev);
50 void toev_stop(TimeoutEvent *toev) {
51 if (!toev->running) return;
53 if (simulate) sim_toev_stop(toev);
54 else events->cancel_time(events, toev->abs, toev_callback, toev);
57 void mgettimeofday(struct timeval *tv) {
59 sim_mgettimeofday(tv);
61 real_mgettimeofday(tv);
63 simlog("timestamp %ld.%06ld\n",tv->tv_sec,tv->tv_usec);