[sr-dev] git:master: core: fork_sync_timer() uses milisecond precision to catch up on delayed execution

Daniel-Constantin Mierla miconda at gmail.com
Wed Jul 30 15:05:09 CEST 2014


Module: sip-router
Branch: master
Commit: d1c97010ed8d3c7a19580c20b8cd81c6a485eadf
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d1c97010ed8d3c7a19580c20b8cd81c6a485eadf

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Wed Jul 30 15:03:45 2014 +0200

core: fork_sync_timer() uses milisecond precision to catch up on delayed execution

- previously was using a step of a second

---

 timer_proc.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/timer_proc.c b/timer_proc.c
index 4d58b1b..85734d2 100644
--- a/timer_proc.c
+++ b/timer_proc.c
@@ -222,16 +222,17 @@ int fork_sync_timer(int child_id, char* desc, int make_sock,
 	if (pid<0) return -1;
 	if (pid==0){
 		/* child */
-		ts2 = interval;
+		ts2 = interval*1000; /* miliseconds */
 		if (cfg_child_init()) return -1;
 		for(;;){
-			if(ts2>0) sleep(ts2);
-			else sleep(1);
-			ts1 = get_ticks();
+			if(ts2>0) sleep_us(ts2*1000); /* microseconds sleep */
+			else sleep_us(1000); /* 1 milisecond sleep to catch up */
+			ts1 = get_ticks_raw();
 			cfg_update();
-			f(get_ticks(), param); /* ticks in s for compatibility with old
+			f(TICKS_TO_S(ts1), param); /* ticks in sec for compatibility with old
 									  timers */
-			ts2 = interval - get_ticks() + ts1;
+			/* convert to mili-seconds and adjust the next sleep duration */
+			ts2 = interval*1000 - TICKS_TO_MS(get_ticks_raw()) + TICKS_TO_MS(ts1);
 		}
 	}
 	/* parent */




More information about the sr-dev mailing list