28 #include <sys/timeb.h> 31 #define MAX_TIMER_QUEUES 16 32 #define SPECIAL_QUEUE 16 33 #define WRITE_QUEUE 17 55 {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
56 {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}
64 static timer_t Timer_id;
93 struct sigaction sig_info;
117 if( timer_queues[
WRITE_QUEUE].queue_head == NULL ) {
128 sigaddset(&
set,SIGIO);
134 sig_info.sa_mask =
set;
136 sig_info.sa_flags = SA_RESTART;
138 sig_info.sa_flags = 0;
140 if( sigaction(SIGALRM, &sig_info, 0) < 0 ) {
141 perror(
"sigaction(SIGALRM)" );
161 void create_alrm_thread(
void);
179 if( timer_queues[
WRITE_QUEUE].queue_head == NULL ) {
192 create_alrm_thread();
228 struct timeb timebuf;
236 secs = (int)timebuf.time;
237 *millies = timebuf.millitm;
240 gettimeofday(&tv, tz);
241 secs = (int)tv.tv_sec;
242 *millies = (
int)tv.tv_usec / 1000;
253 deltat = now - (int)DIM_last_time;
265 DIM_next_time = secs;
271 kill(getpid(),SIGALRM);
276 return((
int)alarm((
unsigned int)secs));
297 struct timeval timeout;
300 timeout.tv_usec = usecs;
301 select(FD_SETSIZE, NULL, NULL, NULL, &timeout);
319 if(DIM_time_left == -1)
325 if(DIM_time_left < 0)
333 else if(DIM_time_left > 0)
337 DIM_time_left = to_go - deltat;
338 if(DIM_time_left <= 0)
364 if( timer_queues[i].queue_head == 0 )
367 if( i == MAX_TIMER_QUEUES )
371 memset( timer_queues[i].queue_head, 0,
sizeof(
TIMR_ENT) );
388 entry = queue_head->
next;
401 TIMR_ENT *new_entry, *queue_head, *auxp, *prevp;
402 int next_time, min_time = 100000;
403 int time_left, deltat = 0;
420 if((next_time > min_time) && (min_time != 0))
421 next_time = min_time;
437 new_entry->
tag = tag;
453 if(time >= auxp->
time)
478 if((next_time != -10) && (min_time == 100000))
481 if(next_time > min_time)
482 next_time = min_time;
492 int time_left, deltat = 0;
505 int time_left, deltat = 0;
526 TIMR_ENT *auxp, *prevp, *queue_head;
559 int min_time = 100000;
564 if((min_time != -10) || deltat)
566 if( (queue_head = timer_queues[
SPECIAL_QUEUE].queue_head) != NULL)
583 if( (queue_head = timer_queues[queue_id].queue_head) == NULL )
598 if(auxp->
time < min_time)
600 min_time = auxp->
time;
603 if((!deltat) && (min_time <= 1))
608 if(min_time == 100000)
638 next_time = new_time;
664 static int curr_queue_id = 0;
666 TIMR_ENT *auxp, *prevp, *queue_head;
684 for(i = 0; i < n; i++)
691 for(i = 0; i < n; i++)
729 if( (queue_head = timer_queues[queue_id].queue_head) == NULL )
732 if((curr_entry) && (queue_id == curr_queue_id))
753 if( timer_queues[queue_id].remove_entries ) {
815 if( entry->
tag == tag )
842 for(i = 0; i < secs*2; i++)
851 sigaddset(&
set,SIGALRM);
852 sigprocmask(SIG_UNBLOCK, &
set, &oset);
857 }
while(Dtq_sleeping);
858 sigprocmask(SIG_SETMASK,&oset,0);
871 }
while(Dtq_sleeping);
static void Std_timer_handler()
int dtq_delete(int queue_id)
DLL * dll_get_prev(DLL *head, DLL *item)
void dll_insert_after(DLL *atitem, DLL *item)
int dtq_task(void *dummy)
void dim_usleep(int usecs)
static time_t DIM_last_time
void dtq_sleep_rout(dim_long tag)
int dim_dtq_init(int thr_flag)
static int get_elapsed_time()
unsigned int dtq_sleep(int secs)
static QUEUE_ENT timer_queues[MAX_TIMER_QUEUES+2]
void dll_remove(DLL *item)
static int DIM_last_time_millies
static int rem_deleted_entries(int queue_id)
static int get_current_time(int *millies)
_DIM_PROTO(static void alrm_sig_handler,(int num))
void dtq_start_timer(int time, void(*user_routine)(), dim_long tag)
static int start_it(int new_time)
int dtq_stop_timer(dim_long tag)
int dtq_clear_entry(TIMR_ENT *entry)
int dtq_rem_entry(int queue_id, TIMR_ENT *entry)
static int get_minimum(int deltat)
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
TIMR_ENT * dtq_add_entry(int queue_id, int time, void(*user_routine)(), dim_long tag)
DLL * dll_get_next(DLL *head, DLL *item)
static int my_alarm(int secs)
struct timer_entry * next
void dummy_alrm_sig_handler(int num)
static void alrm_sig_handler(int num)
static void user_routine(void *tagp, void *bufp, int *size)
struct timer_entry * prev