Browse code

Functions for handling timer lists has been tested and debugged :-)) Bogdan

Bogdan-Andrei Iancu authored on 26/11/2001 20:49:23
Showing 5 changed files
... ...
@@ -13,7 +13,7 @@ depends= $(sources:.c=.d)
13 13
 NAME=tm.so
14 14
 
15 15
 LDFLAGS=-O2 -shared
16
-LIBS=
16
+LIBS= -lpthread
17 17
 
18 18
 ifeq ($(ARCH), SunOS)
19 19
 LDFLAGS=-O2 -G
... ...
@@ -103,6 +103,7 @@ void free_hash_table( struct s_table *hash_table )
103 103
 struct s_table* init_hash_table()
104 104
 {
105 105
    struct s_table*  hash_table;
106
+   pthread_t *thread;
106 107
    int       i;
107 108
 
108 109
    /*allocs the table*/
... ...
@@ -146,10 +147,10 @@ struct s_table* init_hash_table()
146 147
        init_timerlist_lock( hash_table, i );
147 148
     }
148 149
 
149
-#ifdef THREAD
150
+//#ifdef THREAD
150 151
    /* starts the timer thread/ process */
151
-   pthread_create( &(hash_table->timer_thread_id), NULL, timer_routine, hash_table );
152
-#endif
152
+   pthread_create( thread, NULL, timer_routine, hash_table );
153
+//#endif
153 154
 
154 155
    return  hash_table;
155 156
 
... ...
@@ -617,7 +618,7 @@ int t_reply_matching( struct s_table *hash_table , struct sip_msg *p_msg , struc
617 618
             while( p_cell )
618 619
              {
619 620
                 /* the transaction is referenceted for reading */
620
-                ref_Transaction( p_cell );
621
+                ref_transaction( p_cell );
621 622
                 /* is it the cell with the wanted entry_label? */
622 623
                 if ( p_cell->label = entry_label )
623 624
                    /* has the transaction the wanted branch? */
... ...
@@ -625,7 +626,7 @@ int t_reply_matching( struct s_table *hash_table , struct sip_msg *p_msg , struc
625 626
                     {/* WE FOUND THE GOLDEN EGG !!!! */
626 627
                        p_Trans = &p_cell;
627 628
                        *p_branch = branch_id;
628
-                       unref_Transaction( p_cell );
629
+                       unref_transaction( p_cell );
629 630
                        return 1;
630 631
                     }
631 632
 
... ...
@@ -634,7 +635,7 @@ int t_reply_matching( struct s_table *hash_table , struct sip_msg *p_msg , struc
634 635
                p_cell = p_cell->next_cell;
635 636
 
636 637
                /* the transaction is dereferenceted */
637
-               unref_Transaction( tmp_cell );
638
+               unref_transaction( tmp_cell );
638 639
              }
639 640
           }
640 641
       }
... ...
@@ -655,7 +656,7 @@ int t_store_incoming_reply( struct cell* Trans, unsigned int branch, struct sip_
655 656
 {
656 657
    /* if there is a previous reply, replace it */
657 658
    if ( Trans->outbound_response[branch] )
658
-      free_sip_msg( Trans->outbound_response[branch] );
659
+      /*free_sip_msg( Trans->outbound_response[branch] ) TO DO*/ ;
659 660
    Trans->outbound_response[branch] = sip_msg_cloner( p_msg );
660 661
 }
661 662
 
... ...
@@ -779,7 +780,7 @@ void start_FR_timer( struct s_table* hash_table, struct cell* p_cell )
779 780
 {
780 781
 
781 782
    /* adds the cell int FINAL RESPONSE timer list*/
782
-   put_in_tail_of_timer_list( hash_table, p_cell, FR_TIMER_LIST, FR_TIME_OUT + hash_table->time );
783
+   add_to_tail_of_timer_list( hash_table, &(p_cell->tl[FR_TIMER_LIST]), FR_TIMER_LIST, FR_TIME_OUT);
783 784
 
784 785
 }
785 786
 
... ...
@@ -796,10 +797,10 @@ void start_WT_timer( struct s_table* hash_table, struct cell* p_cell )
796 797
    	struct timer* timers= hash_table->timers;
797 798
 
798 799
    	//if is in FR list -> first it must be removed from there
799
-	remove_timer( hash_table, p_cell, FR_TIMER_LIST );
800
+	remove_from_timer_list( hash_table, &(p_cell->tl[FR_TIMER_LIST]), FR_TIMER_LIST );
800 801
 
801 802
    	/* adds the cell int WAIT timer list*/
802
-   	put_in_tail_of_timer_list( hash_table, p_cell, WT_TIMER_LIST, WT_TIME_OUT + hash_table->time );
803
+   	add_to_tail_of_timer_list( hash_table, &(p_cell->tl[WT_TIMER_LIST]), WT_TIMER_LIST, WT_TIME_OUT );
803 804
 }
804 805
 
805 806
 
... ...
@@ -843,7 +844,7 @@ void del_Transaction( struct s_table *hash_table , struct cell * p_cell )
843 844
     if ( ref_counter==0 )
844 845
        free_cell( p_cell );
845 846
      /* else it's added to del hooker list for future del */
846
-    else put_in_tail_of_timer_list( hash_table, p_cell, DELETE_LIST, 0 );
847
+    else add_to_tail_of_timer_list( hash_table, &(p_cell->tl[DELETE_LIST]), DELETE_LIST, 0 );
847 848
 }
848 849
 
849 850
 
... ...
@@ -113,7 +113,7 @@ struct s_table
113 113
 
114 114
 
115 115
 
116
-void free_cell( struct cell* dead_cell );
116
+void free_cell( struct cell* dead_cell );                    
117 117
 struct s_table* init_hash_table();
118 118
 
119 119
 void ref_transaction( struct cell* p_cell);
... ...
@@ -9,8 +9,6 @@
9 9
 */
10 10
 
11 11
 
12
-void * timer_routine(void * attr);
13
-
14 12
 
15 13
 /* put a new cell into a list nr. list_id within a hash_table;
16 14
   * set initial timeout
... ...
@@ -71,6 +69,8 @@ void insert_into_timer_list( struct s_table* hash_table , struct timer_link* new
71 69
       tl->prev_tl = new_tl;
72 70
       if ( new_tl->prev_tl )
73 71
          new_tl->prev_tl->next_tl = new_tl;
72
+      else
73
+         timer_list->first_tl = new_tl;
74 74
       new_tl->next_tl = tl;
75 75
    }
76 76
    else
... ...
@@ -159,7 +159,7 @@ void * timer_routine(void * attr)
159 159
       printf("%d\n", *time);
160 160
 
161 161
       for( id=0 ; id<NR_OF_TIMER_LISTS ; id++ )
162
-         while ( timers[ id ].first_tl->time_out >= *time )
162
+         while ( timers[ id ].first_tl && timers[ id ].first_tl->time_out <= *time )
163 163
          {
164 164
             tl = remove_from_timer_list_from_head( hash_table, id );
165 165
             timers[id].timeout_handler( tl->payload );
... ...
@@ -30,8 +30,8 @@ typedef struct timer_link
30 30
    void                      *payload;
31 31
 }timer_link_type ;
32 32
 
33
-#include "lock.h"
34 33
 
34
+#include "lock.h"
35 35
 
36 36
 /* timer list: includes head, tail and protection semaphore */
37 37
 typedef struct  timer
... ...
@@ -44,10 +44,11 @@ typedef struct  timer
44 44
 
45 45
 
46 46
 
47
-
48
-void add_to_tail_of_timer_list( struct s_table* hash_table , struct timer_link * tl , int list_id, unsigned int time_out );
49
-void insert_into_timer_list( struct s_table* hash_table , struct timer_link* tl, int list_id , unsigned int time_out );
50
-void remove_from_timer_list( struct s_table* hash_table , struct timer_link* tl , int list_id);
47
+void                        add_to_tail_of_timer_list( struct s_table* hash_table , struct timer_link * tl , int list_id, unsigned int time_out );
48
+void                        insert_into_timer_list( struct s_table* hash_table , struct timer_link* tl, int list_id , unsigned int time_out );
49
+void                        remove_from_timer_list( struct s_table* hash_table , struct timer_link* tl , int list_id);
51 50
 struct timer_link  *remove_from_timer_list_from_head( struct s_table* hash_table, int list_id );
51
+void                       *timer_routine(void * attr);
52
+
52 53
 
53 54
 #endif