[sr-dev] git:master:98ea3b05: core: allow a worker id in timer routines

Henning Westerholt henningw at users.noreply.github.com
Sat Mar 9 12:52:49 CET 2019


Module: kamailio
Branch: master
Commit: 98ea3b05528d0277ebe9618e43df301411e38210
URL: https://github.com/kamailio/kamailio/commit/98ea3b05528d0277ebe9618e43df301411e38210

Author: lazedo <luis.azedo at factorlusitano.com>
Committer: Henning Westerholt <henningw at users.noreply.github.com>
Date: 2019-03-09T12:52:43+01:00

core: allow a worker id in timer routines

---

Modified: src/core/timer.h
Modified: src/core/timer_proc.c
Modified: src/core/timer_proc.h

---

Diff:  https://github.com/kamailio/kamailio/commit/98ea3b05528d0277ebe9618e43df301411e38210.diff
Patch: https://github.com/kamailio/kamailio/commit/98ea3b05528d0277ebe9618e43df301411e38210.patch

---

diff --git a/src/core/timer.h b/src/core/timer.h
index 3b1669ab19..2c7f330f89 100644
--- a/src/core/timer.h
+++ b/src/core/timer.h
@@ -62,6 +62,7 @@ extern pid_t slow_timer_pid;
 
 /* deprecated, old, kept for compatibility */
 typedef void (timer_function)(unsigned int ticks, void* param);
+typedef void (timer_function_w)(unsigned int ticks, int worker, void* param);
 /* deprecated, old, kept for compatibility
 	get_ticks()*TIMER_TICK used to be the time in s
 	for new code, use get_ticks_raw() and one of the macros defined in
@@ -70,6 +71,7 @@ typedef void (timer_function)(unsigned int ticks, void* param);
 
 /*function prototype to execute on mili-second based basic timers */
 typedef void (utimer_function)(unsigned int uticks, void* param);
+typedef void (utimer_function_w)(unsigned int uticks, int worker, void* param);
 
 struct timer_ln; /* forward decl */
 /* new
diff --git a/src/core/timer_proc.c b/src/core/timer_proc.c
index 20c50e0dcd..d153c635cc 100644
--- a/src/core/timer_proc.c
+++ b/src/core/timer_proc.c
@@ -84,6 +84,27 @@ int fork_basic_timer(int child_id, char* desc, int make_sock,
 	return pid;
 }
 
+int fork_basic_timer_w(int child_id, char* desc, int make_sock,
+						timer_function_w* f, int worker, void* param, int interval)
+{
+	int pid;
+
+	pid=fork_process(child_id, desc, make_sock);
+	if (pid<0) return -1;
+	if (pid==0){
+		/* child */
+		if (cfg_child_init()) return -1;
+		for(;;){
+			sleep(interval);
+			cfg_update();
+			f(get_ticks(), worker, param); /* ticks in s for compatibility with old
+									* timers */
+		}
+	}
+	/* parent */
+	return pid;
+}
+
 /**
  * \brief Forks a separate simple microsecond-sleep() periodic timer
  *
@@ -123,6 +144,28 @@ int fork_basic_utimer(int child_id, char* desc, int make_sock,
 	return pid;
 }
 
+int fork_basic_utimer_w(int child_id, char* desc, int make_sock,
+						utimer_function_w* f, int worker, void* param, int uinterval)
+{
+	int pid;
+	ticks_t ts;
+
+	pid=fork_process(child_id, desc, make_sock);
+	if (pid<0) return -1;
+	if (pid==0){
+		/* child */
+		if (cfg_child_init()) return -1;
+		for(;;){
+			sleep_us(uinterval);
+			cfg_update();
+			ts = get_ticks_raw();
+			f(TICKS_TO_MS(ts), worker, param); /* ticks in mili-seconds */
+		}
+	}
+	/* parent */
+	return pid;
+}
+
 
 /**
  * \brief Forks a timer process based on the local timer
diff --git a/src/core/timer_proc.h b/src/core/timer_proc.h
index baaf366564..8c4c6fa3ee 100644
--- a/src/core/timer_proc.h
+++ b/src/core/timer_proc.h
@@ -58,6 +58,8 @@ int register_basic_timers(int timers);
  */
 int fork_basic_timer(int child_id, char* desc, int make_sock,
 						timer_function* f, void* param, int interval);
+int fork_basic_timer_w(int child_id, char* desc, int make_sock,
+						timer_function_w* f, int worker, void* param, int interval);
 
 #define fork_dummy_timer fork_basic_timer
 
@@ -80,6 +82,8 @@ int fork_basic_timer(int child_id, char* desc, int make_sock,
  */
 int fork_basic_utimer(int child_id, char* desc, int make_sock,
 						timer_function* f, void* param, int uinterval);
+int fork_basic_utimer_w(int child_id, char* desc, int make_sock,
+						timer_function_w* f, int worker, void* param, int uinterval);
 /**
  * \brief Forks a timer process based on the local timer
  *




More information about the sr-dev mailing list