e0ccfb04f731a0771b0c3a5f6ffa17db5b8984c5
[sip-router] / modules / tm / timer.h
1 /*
2  * $Id$
3  */
4
5 #ifndef _TIMER_H
6 #define _TIMER_H
7
8 #include "lock.h"
9
10 /* identifiers of timer lists; 
11 */
12 enum lists {    FR_TIMER_LIST, FR_INV_TIMER_LIST,
13                                 WT_TIMER_LIST, DELETE_LIST, 
14                                 /* fixed-timer retransmission lists (benefit: fixed timer
15                                    length allows for appending new items to the list as
16                                         opposed to inserting them which is costly */
17                                 RT_T1_TO_1, RT_T1_TO_2, RT_T1_TO_3, RT_T2, 
18                                 NR_OF_TIMER_LISTS };
19
20 #define is_in_timer_list2(_tl) ( (_tl)->list )
21
22
23 struct timer;
24
25 /* all you need to put a cell in a timer list:
26    links to neighbours and timer value         */
27 typedef struct timer_link
28 {
29         struct timer_link       *next_tl;
30         struct timer_link       *prev_tl;
31         unsigned int            time_out;
32         void                            *payload;
33         struct timer            *list;
34 }timer_link_type ;
35
36
37 /* timer list: includes head, tail and protection semaphore */
38 typedef struct  timer
39 {
40    struct timer_link first_tl;
41    struct timer_link last_tl;
42    ser_lock_t             mutex;
43    enum lists id;
44    void                      (*timeout_handler)(void*);
45 } timer_type;
46
47 void init_timer_list( struct s_table* hash_table, enum lists list_id);
48 void reset_timer_list( struct s_table* hash_table, enum lists list_id);
49
50 void add_to_tail_of_timer_list( struct timer *timer_list, 
51         struct timer_link *tl, unsigned int time_out );
52 void remove_from_timer_list( struct timer_link *tl);
53 void timer_routine(unsigned int, void *);
54
55
56 /* deprecated -- too expensive -- use appending instead 
57 void insert_into_timer_list( struct s_table* hash_table , 
58         struct timer_link* tl, enum lists list_id , unsigned int time_out );
59 */
60
61 #endif