@@ -77,7 +77,7 @@ static int mod_init(void);
77
77
static void mod_destroy (void );
78
78
static int child_init (int rank );
79
79
80
- void timer_check (unsigned int ticks , void * param );
80
+ void timer_check (unsigned int ticks , void * hash_counter );
81
81
82
82
static struct mi_root * mi_reg_list (struct mi_root * cmd , void * param );
83
83
static struct mi_root * mi_reg_reload (struct mi_root * cmd , void * param );
@@ -93,7 +93,6 @@ unsigned int timer_interval = 100;
93
93
94
94
reg_table_t reg_htable = NULL ;
95
95
unsigned int reg_hsize = 1 ;
96
- unsigned int hash_index = 0 ;
97
96
98
97
static str db_url = {NULL , 0 };
99
98
@@ -186,6 +185,7 @@ struct module_exports exports= {
186
185
static int mod_init (void )
187
186
{
188
187
unsigned int _timer ;
188
+ int * param ;
189
189
190
190
if (load_uac_auth_api (& uac_auth_api )< 0 ){
191
191
LM_ERR ("Failed to load uac_auth api\n" );
@@ -234,9 +234,18 @@ static int mod_init(void)
234
234
return -1 ;
235
235
}
236
236
237
+ /* allocate a shm variable to keep the counter used by the timer
238
+ * routine - it must be shared as the routine get executed
239
+ * in different processes */
240
+ if (NULL == (param = (int * ) shm_malloc (sizeof (int )))) {
241
+ LM_ERR ("cannot allocate shm memory for keepalive counter\n" );
242
+ return -1 ;
243
+ }
244
+ * param = 0 ;
245
+
237
246
_timer = timer_interval /reg_hsize ;
238
247
if (_timer ) {
239
- register_timer ("uac_reg_check" , timer_check , 0 , _timer ,
248
+ register_timer ("uac_reg_check" , timer_check , ( void * )( long ) param , _timer ,
240
249
TIMER_FLAG_DELAY_ON_DELAY );
241
250
} else {
242
251
LM_ERR ("timer_interval=[%d] MUST be bigger then reg_hsize=[%d]\n" ,
@@ -625,15 +634,16 @@ int send_register(unsigned int hash_index, reg_record_t *rec, str *auth_hdr)
625
634
struct timer_check_data {
626
635
time_t now ;
627
636
str * s_now ;
637
+ int hash_counter ;
628
638
};
629
639
630
640
int run_timer_check (void * e_data , void * data , void * r_data )
631
641
{
632
- unsigned int i = hash_index ;
633
642
reg_record_t * rec = (reg_record_t * )e_data ;
634
643
struct timer_check_data * t_check_data = (struct timer_check_data * )data ;
635
644
time_t now = t_check_data -> now ;
636
645
str * s_now = t_check_data -> s_now ;
646
+ unsigned int i = t_check_data -> hash_counter ;
637
647
638
648
switch (rec -> state ){
639
649
case REGISTERING_STATE :
@@ -675,16 +685,17 @@ int run_timer_check(void *e_data, void *data, void *r_data)
675
685
}
676
686
677
687
678
- void timer_check (unsigned int ticks , void * param )
688
+ void timer_check (unsigned int ticks , void * hash_counter )
679
689
{
680
- unsigned int i = hash_index ;
690
+ unsigned int i = * ( unsigned * )( unsigned long * ) hash_counter ;
681
691
char * p ;
682
692
int len , ret ;
683
693
time_t now ;
684
694
str str_now = {NULL , 0 };
685
695
struct timer_check_data t_check_data ;
686
696
687
697
now = time (0 );
698
+ * (unsigned * )(unsigned long * )hash_counter = (i + 1 )%reg_hsize ;
688
699
689
700
p = int2str ((unsigned long )(time (0 )), & len );
690
701
if (p && len > 0 ) {
@@ -701,6 +712,7 @@ void timer_check(unsigned int ticks, void* param)
701
712
/* Initialize slinkedl run traversal data */
702
713
t_check_data .now = now ;
703
714
t_check_data .s_now = & str_now ;
715
+ t_check_data .hash_counter = i ;
704
716
705
717
LM_DBG ("checking ... [%d] on htable[%d]\n" , (unsigned int )now , i );
706
718
lock_get (& reg_htable [i ].lock );
@@ -711,8 +723,6 @@ void timer_check(unsigned int ticks, void* param)
711
723
712
724
if (str_now .s ) {pkg_free (str_now .s );}
713
725
714
- hash_index = (++ i )%reg_hsize ;
715
-
716
726
return ;
717
727
}
718
728
0 commit comments