Jiri Kuthan authored on 08/12/2001 02:29:14
Showing 6 changed files
... ...
@@ -66,7 +66,6 @@ void free_hash_table( struct s_table *hash_table )
66 66
 {
67 67
    struct cell* p_cell;
68 68
    struct cell* tmp_cell;
69
-   struct timer_link *tl;
70 69
    int   i;
71 70
 
72 71
    if (hash_table)
... ...
@@ -84,8 +83,14 @@ void free_hash_table( struct s_table *hash_table )
84 83
       }
85 84
 
86 85
       /* deletes all cells from DELETE_LIST list (they are no more accessible from enrys) */
86
+        lock( hash_table->timers[DELETE_LIST].mutex );
87
+        remove_delete_list( hash_table );
88
+        unlock( hash_table->timers[DELETE_LIST].mutex );
89
+
90
+      /*
87 91
       while( (tl=remove_from_timer_list_from_head( hash_table, DELETE_LIST ))!=0 )
88 92
          free_cell( p_cell ) ;
93
+      */
89 94
 
90 95
       /* the mutexs for sync the lists are released*/
91 96
       for ( i=0 ; i<NR_OF_TIMER_LISTS ; i++ )
... ...
@@ -212,11 +212,14 @@ tryagain:
212 212
 int init_cell_lock( struct cell *cell )
213 213
 {
214 214
 	/* just advice which of the available semaphores to use;
215
-	   specifically, all cells in an entry use the same one
216
-	   shared with its entry lock
215
+		shared with the lock belonging to the next hash entry lock
216
+            (so that there are no collisions if one wants to try to
217
+             lock on a cell as well as its list)
218
+
217 219
         */
218 220
 	cell->mutex.semaphore_set=entry_semaphore,
219
-	cell->mutex.semaphore_index=cell->hash_index / sem_nr;
221
+	cell->mutex.semaphore_index=(cell->hash_index % sem_nr + 1)%sem_nr;
222
+
220 223
 }
221 224
 
222 225
 int init_entry_lock( struct s_table* hash_table, struct entry *entry )
... ...
@@ -226,9 +229,9 @@ int init_entry_lock( struct s_table* hash_table, struct entry *entry )
226 229
 	   many partitions as number of available semaphors allows
227 230
         */
228 231
 	entry->mutex.semaphore_set=entry_semaphore;
229
-	entry->mutex.semaphore_index =
230
-		((void *)entry - (void *)(hash_table->entrys ) )
231
-			/ ( sizeof(struct entry) * sem_nr );
232
+	entry->mutex.semaphore_index = ( ((void *)entry - (void *)(hash_table->entrys ) )
233
+               / sizeof(struct entry) ) % sem_nr;
234
+
232 235
 }
233 236
 
234 237
 int init_timerlist_lock( struct s_table* hash_table, enum lists timerlist_id)
... ...
@@ -8,7 +8,6 @@
8 8
 
9 9
 #include "../../shm_mem.h"
10 10
 
11
-/*
12 11
 #if defined SHM_MEM
13 12
 
14 13
 #include "../../shm_mem.h"
... ...
@@ -17,7 +16,6 @@
17 16
 #define sh_free(ptr)		shm_free((ptr))
18 17
 
19 18
 #else
20
-*/
21 19
 
22 20
 #include <stdlib.h>
23 21
 
... ...
@@ -26,17 +24,4 @@
26 24
 
27 25
 #endif
28 26
 
29
-/*
30
-#ifdef MEM_DBG
31
-
32
-#include <stdlib.h>
33
-
34
-#define sh_malloc(size)		({ void *_p=malloc((size)); \
35
-				  printf("MEMDBG: malloc (%d): %p\n", (size), _p); \
36
-				  _p; })
37
-
38
-#define sh_free(ptr)		({ printf("MEMDBG: free: %p\n", (ptr)); free((ptr)); })
39
-
40
-
41 27
 #endif
42
-*/
... ...
@@ -47,41 +47,26 @@ void insert_into_timer_list( struct s_table* hash_table , struct timer_link* new
47 47
    new_tl->time_out = time_out ;
48 48
    DBG("DEBUG: insert_into_timer[%d]: %d, %p\n",list_id,new_tl->time_out,new_tl);
49 49
 
50
-   /* if we have an empty list*/
51
-   if ( !timer_list->first_tl )
52
-   {
53
-      new_tl->next_tl= 0;
54
-      new_tl->prev_tl = 0;
55
-      lock( timer_list->mutex );
56
-      timer_list->first_tl = new_tl;
57
-      timer_list->last_tl = new_tl;
58
-      unlock( timer_list->mutex );
59
-      return;
60
-   }
61 50
 
62
-   for( tl=timer_list->first_tl ; tl && tl->time_out<new_tl->time_out ; tl=tl->next_tl );
51
+       lock( timer_list->mutex );
52
+       for( tl=timer_list->first_tl ; tl && tl->time_out<new_tl->time_out ; 
53
+               tl=tl->next_tl );
54
+       if ( tl ) {
55
+               /* insert before tl*/
56
+               new_tl->prev_tl = tl->prev_tl;
57
+               tl->prev_tl = new_tl;
58
+       } else { /* at the end or empty list */
59
+               new_tl->prev_tl = timer_list->last_tl;
60
+               new_tl->next_tl = NULL;
61
+               timer_list->last_tl = new_tl;
62
+       }
63
+       if (new_tl->prev_tl ) 
64
+               new_tl->prev_tl->next_tl = new_tl;
65
+       else
66
+               timer_list->first_tl = new_tl;
67
+       new_tl->next_tl = new_tl;
68
+       unlock( timer_list->mutex );
63 69
 
64
-   lock( timer_list->mutex );
65
-   if ( tl )
66
-   {
67
-      /* insert before tl*/
68
-      new_tl->prev_tl = tl->prev_tl;
69
-      tl->prev_tl = new_tl;
70
-      if ( new_tl->prev_tl )
71
-         new_tl->prev_tl->next_tl = new_tl;
72
-      else
73
-         timer_list->first_tl = new_tl;
74
-      new_tl->next_tl = tl;
75
-   }
76
-   else
77
-   {
78
-      /* insert at the end */
79
-      new_tl->next_tl = 0;
80
-      new_tl->prev_tl = timer_list->last_tl;
81
-      timer_list->last_tl->next_tl = new_tl;
82
-      timer_list->last_tl = new_tl ;
83
-    }
84
-    unlock( timer_list->mutex );
85 70
 }
86 71
 
87 72
 
... ...
@@ -159,3 +144,15 @@ void timer_routine(unsigned int ticks , void * attr)
159 144
          }
160 145
 }
161 146
 
147
+void remove_delete_list( struct s_table *hash_table )
148
+{
149
+        struct timer_link *tl;
150
+
151
+        /* lock( hash_table->timers[DELETE_LIST].mutex );*/
152
+        while( tl=remove_from_timer_list_from_head( hash_table, DELETE_LIST ) ) {
153
+                free_cell( (struct cell *) tl->payload );
154
+        }
155
+        /* unlock( hash_table->timers[DELETE_LIST].mutex ); */
156
+}
157
+
158
+
... ...
@@ -56,5 +56,7 @@ void                        remove_from_timer_list( struct s_table* hash_table ,
56 56
 struct timer_link  *remove_from_timer_list_from_head( struct s_table* hash_table, int list_id );
57 57
 void                       timer_routine(unsigned int, void *);
58 58
 
59
+void remove_delete_list( struct s_table *hash_table );
60
+
59 61
 
60 62
 #endif
... ...
@@ -1,4 +1,4 @@
1
-debug=9          # debug level (cmd line: -dddddddddd)
1
+debug=2          # debug level (cmd line: -dddddddddd)
2 2
 log_stderror=yes # (cmd line: -E)
3 3
 check_via=yes     # (cmd. line: -v)
4 4
 dns=on           # (cmd. line: -r)
... ...
@@ -17,7 +17,9 @@ route{
17 17
 	if ( t_lookup_request()) {
18 18
 		if ( method=="ACK" )	{
19 19
 			t_release();
20
-			t_forward("195.37.77.100", "5090" );
20
+			forward(195.37.77.100, 5090 );
21
+# once it supports ACK too
22
+#			t_forward(195.37.77.100, 5090 );
21 23
 		} else {
22 24
 			t_retransmit_reply();
23 25
 		};
... ...
@@ -27,7 +29,6 @@ route{
27 29
 		} else {
28 30
 			t_add_transaction();
29 31
 			if (method=="CANCEL") {
30
-				log("SER: new CANCEL\n");
31 32
 				t_send_reply( "200", "glad to cancel");
32 33
 			} else {
33 34
 				t_send_reply("100", "trying -- your call is important to us");