]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sched: make sure scheduler parameter change handler is first
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 19 Aug 2014 09:45:30 +0000 (11:45 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 20 Aug 2014 14:54:26 +0000 (16:54 +0200)
This is needed to allow other handlers to add new timers.

local.c
local.h
sched.c

diff --git a/local.c b/local.c
index ee70dacd6cd49134ee0a6a5fbc0c5af7ab89e45e..5a3fb4360fb53088ef1f1bda571c930c462f7f47 100644 (file)
--- a/local.c
+++ b/local.c
@@ -252,6 +252,14 @@ void LCL_RemoveParameterChangeHandler(LCL_ParameterChangeHandler handler, void *
 
 /* ================================================== */
 
+int
+LCL_IsFirstParameterChangeHandler(LCL_ParameterChangeHandler handler)
+{
+  return change_list.next->handler == handler;
+}
+
+/* ================================================== */
+
 static void
 invoke_parameter_change_handlers(struct timeval *raw, struct timeval *cooked,
                                  double dfreq, double doffset,
diff --git a/local.h b/local.h
index 6209510095b3b23d3fb891c4a62bda1b56fa0c21..aff9004fe5d1c724febdee524c203279e6b9e67a 100644 (file)
--- a/local.h
+++ b/local.h
@@ -92,6 +92,9 @@ extern void LCL_AddParameterChangeHandler(LCL_ParameterChangeHandler handler, vo
 /* Remove a handler */
 extern void LCL_RemoveParameterChangeHandler(LCL_ParameterChangeHandler, void *anything);
 
+/* Check if a handler is invoked first when dispatching */
+extern int LCL_IsFirstParameterChangeHandler(LCL_ParameterChangeHandler handler);
+
 /* Function type for handlers to be called back when an indeterminate
    offset is introduced into the local time.  This situation occurs
    when the frequency must be adjusted to effect a clock slew and
diff --git a/sched.c b/sched.c
index 81b58f71de77a9802b69c575188a5e247d0c8341..16a451abbdbab11fb0caece6a0db7b9158bb2136 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -514,6 +514,10 @@ handle_slew(struct timeval *raw,
   int i;
 
   if (change_type != LCL_ChangeAdjust) {
+    /* Make sure this handler is invoked first in order to not shift new timers
+       added from other handlers */
+    assert(LCL_IsFirstParameterChangeHandler(handle_slew));
+
     /* If a step change occurs, just shift all raw time stamps by the offset */
     
     for (ptr = timer_queue.next; ptr != &timer_queue; ptr = ptr->next) {