memory access syncing protection added
[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 {
13         FR_TIMER_LIST, FR_INV_TIMER_LIST,
14         WT_TIMER_LIST, 
15         DELETE_LIST, 
16         /* fixed-timer retransmission lists (benefit: fixed timer
17            length allows for appending new items to the list as
18                 opposed to inserting them which is costly */
19         RT_T1_TO_1, RT_T1_TO_2, RT_T1_TO_3, RT_T2, 
20         NR_OF_TIMER_LISTS };
21
22
23 extern int timer_group[NR_OF_TIMER_LISTS];
24
25 #define is_in_timer_list2(_tl) ( (_tl)->timer_list )
26
27
28 struct timer;
29
30 /* all you need to put a cell in a timer list:
31    links to neighbours and timer value         */
32 typedef struct timer_link
33 {
34         struct timer_link       *next_tl;
35         struct timer_link       *prev_tl;
36         unsigned int            time_out;
37         void                            *payload;
38         struct timer            *timer_list;
39         /* ser_lock_t                   *mutex; */
40         enum timer_groups       tg;
41 }timer_link_type ;
42
43
44 /* timer list: includes head, tail and protection semaphore */
45 typedef struct  timer
46 {
47    struct timer_link first_tl;
48    struct timer_link last_tl;
49    ser_lock_t             mutex;
50    enum lists id;
51    void                      (*timeout_handler)(void*);
52 } timer_type;
53
54 void init_timer_list( struct s_table* hash_table, enum lists list_id);
55 void reset_timer_list( struct s_table* hash_table, enum lists list_id);
56
57 /*
58 void add_to_tail_of_timer_list( struct timer *timer_list, 
59         struct timer_link *tl, unsigned int time_out );
60 void remove_from_timer_list( struct timer_link *tl);
61 */
62 void timer_routine(unsigned int, void *);
63
64 void remove_timer_unsafe(  struct timer_link* tl ) ;
65 void add_timer_unsafe( struct timer *timer_list,
66         struct timer_link *tl, unsigned int time_out );
67
68
69
70 /* deprecated -- too expensive -- use appending instead 
71 void insert_into_timer_list( struct s_table* hash_table , 
72         struct timer_link* tl, enum lists list_id , unsigned int time_out );
73 */
74
75 #endif