Pārlūkot izejas kodu

htable: ability to create more than one timer process

Daniel-Constantin Mierla 9 gadi atpakaļ
vecāks
revīzija
d8b78bfaab
2 mainītis faili ar 18 papildinājumiem un 7 dzēšanām
  1. 10 2
      modules/htable/ht_api.c
  2. 8 5
      modules/htable/htable.c

+ 10 - 2
modules/htable/ht_api.c

@@ -964,6 +964,8 @@ int ht_has_autoexpire(void)
 	return 0;
 }
 
+extern int ht_timer_procs;
+
 void ht_timer(unsigned int ticks, void *param)
 {
 	ht_t *ht;
@@ -971,18 +973,24 @@ void ht_timer(unsigned int ticks, void *param)
 	ht_cell_t *it0;
 	time_t now;
 	int i;
+	int istart;
+	int istep;
 
 	if(_ht_root==NULL)
 		return;
 
 	now = time(NULL);
-	
+
+	istart = (int)(long)param;
+	if(ht_timer_procs<=0) istep = 1;
+	else istep = ht_timer_procs;
+
 	ht = _ht_root;
 	while(ht)
 	{
 		if(ht->htexpire>0)
 		{
-			for(i=0; i<ht->htsize; i++)
+			for(i=istart; i<ht->htsize; i+=istep)
 			{
 				/* free entries */
 				ht_slot_lock(ht, i);

+ 8 - 5
modules/htable/htable.c

@@ -212,7 +212,7 @@ static int mod_init(void)
 				return -1;
 			}
 		} else {
-			register_sync_timers(1);
+			register_sync_timers(ht_timer_procs);
 		}
 	}
 
@@ -232,15 +232,18 @@ static int child_init(int rank)
 	struct sip_msg *fmsg;
 	struct run_act_ctx ctx;
 	int rtb, rt;
+	int i;
 
 	LM_DBG("rank is (%d)\n", rank);
 
 	if(rank==PROC_MAIN) {
 		if(ht_timer_procs>0) {
-			if(fork_sync_timer(PROC_TIMER, "HTable Timer", 1 /*socks flag*/,
-					ht_timer, NULL, ht_timer_interval)<0) {
-				LM_ERR("failed to start timer routine as process\n");
-				return -1; /* error */
+			for(i=0; i<ht_timer_procs; i++) {
+				if(fork_sync_timer(PROC_TIMER, "HTable Timer", 1 /*socks flag*/,
+						ht_timer, (void*)(long)i, ht_timer_interval)<0) {
+					LM_ERR("failed to start timer routine as process\n");
+					return -1; /* error */
+				}
 			}
 		}
 	}