Browse code

htable: ability to create more than one timer process

Daniel-Constantin Mierla authored on 13/11/2015 08:16:35
Showing 2 changed files
... ...
@@ -964,6 +964,8 @@ int ht_has_autoexpire(void)
964 964
 	return 0;
965 965
 }
966 966
 
967
+extern int ht_timer_procs;
968
+
967 969
 void ht_timer(unsigned int ticks, void *param)
968 970
 {
969 971
 	ht_t *ht;
... ...
@@ -971,18 +973,24 @@ void ht_timer(unsigned int ticks, void *param)
971 971
 	ht_cell_t *it0;
972 972
 	time_t now;
973 973
 	int i;
974
+	int istart;
975
+	int istep;
974 976
 
975 977
 	if(_ht_root==NULL)
976 978
 		return;
977 979
 
978 980
 	now = time(NULL);
979
-	
981
+
982
+	istart = (int)(long)param;
983
+	if(ht_timer_procs<=0) istep = 1;
984
+	else istep = ht_timer_procs;
985
+
980 986
 	ht = _ht_root;
981 987
 	while(ht)
982 988
 	{
983 989
 		if(ht->htexpire>0)
984 990
 		{
985
-			for(i=0; i<ht->htsize; i++)
991
+			for(i=istart; i<ht->htsize; i+=istep)
986 992
 			{
987 993
 				/* free entries */
988 994
 				ht_slot_lock(ht, i);
... ...
@@ -212,7 +212,7 @@ static int mod_init(void)
212 212
 				return -1;
213 213
 			}
214 214
 		} else {
215
-			register_sync_timers(1);
215
+			register_sync_timers(ht_timer_procs);
216 216
 		}
217 217
 	}
218 218
 
... ...
@@ -232,15 +232,18 @@ static int child_init(int rank)
232 232
 	struct sip_msg *fmsg;
233 233
 	struct run_act_ctx ctx;
234 234
 	int rtb, rt;
235
+	int i;
235 236
 
236 237
 	LM_DBG("rank is (%d)\n", rank);
237 238
 
238 239
 	if(rank==PROC_MAIN) {
239 240
 		if(ht_timer_procs>0) {
240
-			if(fork_sync_timer(PROC_TIMER, "HTable Timer", 1 /*socks flag*/,
241
-					ht_timer, NULL, ht_timer_interval)<0) {
242
-				LM_ERR("failed to start timer routine as process\n");
243
-				return -1; /* error */
241
+			for(i=0; i<ht_timer_procs; i++) {
242
+				if(fork_sync_timer(PROC_TIMER, "HTable Timer", 1 /*socks flag*/,
243
+						ht_timer, (void*)(long)i, ht_timer_interval)<0) {
244
+					LM_ERR("failed to start timer routine as process\n");
245
+					return -1; /* error */
246
+				}
244 247
 			}
245 248
 		}
246 249
 	}