Browse code

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

- previously was using a step of a second

Daniel-Constantin Mierla authored on 30/07/2014 13:03:45
Showing 1 changed files
... ...
@@ -222,16 +222,17 @@ int fork_sync_timer(int child_id, char* desc, int make_sock,
222 222
 	if (pid<0) return -1;
223 223
 	if (pid==0){
224 224
 		/* child */
225
-		ts2 = interval;
225
+		ts2 = interval*1000; /* miliseconds */
226 226
 		if (cfg_child_init()) return -1;
227 227
 		for(;;){
228
-			if(ts2>0) sleep(ts2);
229
-			else sleep(1);
230
-			ts1 = get_ticks();
228
+			if(ts2>0) sleep_us(ts2*1000); /* microseconds sleep */
229
+			else sleep_us(1000); /* 1 milisecond sleep to catch up */
230
+			ts1 = get_ticks_raw();
231 231
 			cfg_update();
232
-			f(get_ticks(), param); /* ticks in s for compatibility with old
232
+			f(TICKS_TO_S(ts1), param); /* ticks in sec for compatibility with old
233 233
 									  timers */
234
-			ts2 = interval - get_ticks() + ts1;
234
+			/* convert to mili-seconds and adjust the next sleep duration */
235
+			ts2 = interval*1000 - TICKS_TO_MS(get_ticks_raw()) + TICKS_TO_MS(ts1);
235 236
 		}
236 237
 	}
237 238
 	/* parent */