(client/server or symmetric active peer) */
OperatingMode opmode; /* Whether we are sampling this source
or not and in what way */
- int timer_running; /* Boolean indicating whether we have a timeout
- pending to transmit to the source */
SCH_TimeoutID timeout_id; /* Scheduler's timeout ID, if we are
running on a timer. */
int tx_suspended; /* Boolean indicating we can't transmit yet */
{
/* Check if we can transmit */
if (inst->tx_suspended) {
- assert(!inst->timer_running);
+ assert(!inst->timeout_id);
return;
}
/* Stop old timer if running */
- if (inst->timer_running)
- SCH_RemoveTimeout(inst->timeout_id);
+ SCH_RemoveTimeout(inst->timeout_id);
/* Start new timer for transmission */
inst->timeout_id = SCH_AddTimeoutInClass(delay, SAMPLING_SEPARATION,
SAMPLING_RANDOMNESS,
SCH_NtpSamplingClass,
transmit_timeout, (void *)inst);
- inst->timer_running = 1;
}
/* ================================================== */
static void
start_initial_timeout(NCR_Instance inst)
{
- if (!inst->timer_running) {
+ if (!inst->timeout_id) {
/* This will be the first transmission after mode change */
/* Mark source active */
take_offline(NCR_Instance inst)
{
inst->opmode = MD_OFFLINE;
- if (inst->timer_running) {
- SCH_RemoveTimeout(inst->timeout_id);
- inst->timer_running = 0;
- }
+
+ SCH_RemoveTimeout(inst->timeout_id);
+ inst->timeout_id = 0;
/* Mark source unreachable */
SRC_ResetReachability(inst->source);
&result->remote_addr.ip_addr,
params->min_samples, params->max_samples);
- result->timer_running = 0;
result->timeout_id = 0;
result->tx_suspended = 1;
result->opmode = params->online ? MD_ONLINE : MD_OFFLINE;
instance->local_poll = instance->minpoll;
/* The timer was set with a longer poll interval, restart it */
- if (instance->timer_running)
+ if (instance->timeout_id)
restart_timeout(instance, get_transmit_delay(instance, 0, 0.0));
}
}
NCR_Instance inst = (NCR_Instance) arg;
int sent;
- inst->timer_running = 0;
+ inst->timeout_id = 0;
switch (inst->opmode) {
case MD_BURST_WAS_ONLINE:
}
/* Get rid of old timeout and start a new one */
- assert(inst->timer_running);
+ assert(inst->timeout_id);
restart_timeout(inst, delay_time);
}
static int leap_in_progress;
/* Timer for the leap second handler */
-static int leap_timer_running;
static SCH_TimeoutID leap_timeout_id;
/* Name of a system timezone containing leap seconds occuring at midnight */
enable_local_stratum = CNF_AllowLocalReference(&local_stratum);
- leap_timer_running = 0;
+ leap_timeout_id = 0;
leap_in_progress = 0;
leap_mode = CNF_GetLeapSecMode();
/* Switch to step mode if the system driver doesn't support leap */
fb_drifts = MallocArray(struct fb_drift, fb_drift_max - fb_drift_min + 1);
memset(fb_drifts, 0, sizeof (struct fb_drift) * (fb_drift_max - fb_drift_min + 1));
next_fb_drift = 0;
- fb_drift_timeout_id = -1;
+ fb_drift_timeout_id = 0;
}
last_ref_update.tv_sec = 0;
next_fb_drift = 0;
}
- if (fb_drift_timeout_id != -1) {
- SCH_RemoveTimeout(fb_drift_timeout_id);
- fb_drift_timeout_id = -1;
- }
+ SCH_RemoveTimeout(fb_drift_timeout_id);
+ fb_drift_timeout_id = 0;
if (update_interval < 1.0 || update_interval > last_ref_update_interval * 4.0)
return;
{
assert(next_fb_drift >= fb_drift_min && next_fb_drift <= fb_drift_max);
- fb_drift_timeout_id = -1;
+ fb_drift_timeout_id = 0;
DEBUG_LOG(LOGF_Reference, "Fallback drift %d active: %f ppm",
next_fb_drift, fb_drifts[next_fb_drift - fb_drift_min].freq);
double unsynchronised;
struct timeval when;
- if (fb_drift_timeout_id != -1)
+ if (fb_drift_timeout_id)
return; /* already scheduled */
UTI_DiffTimevalsToDouble(&unsynchronised, now, &last_ref_update);
static void
leap_end_timeout(void *arg)
{
- leap_timer_running = 0;
+ leap_timeout_id = 0;
leap_in_progress = 0;
our_leap_sec = 0;
struct timeval when;
/* Stop old timer if there is one */
- if (leap_timer_running) {
- SCH_RemoveTimeout(leap_timeout_id);
- leap_timer_running = 0;
- leap_in_progress = 0;
- }
+ SCH_RemoveTimeout(leap_timeout_id);
+ leap_timeout_id = 0;
+ leap_in_progress = 0;
if (!our_leap_sec)
return;
}
leap_timeout_id = SCH_AddTimeout(&when, leap_start_timeout, NULL);
- leap_timer_running = 1;
}
/* ================================================== */
static int measurement_period = LOWEST_MEASUREMENT_PERIOD;
-static int timeout_running = 0;
-static SCH_TimeoutID timeout_id;
+static SCH_TimeoutID timeout_id = 0;
static int skip_interrupts;
void
RTC_Linux_Finalise(void)
{
- if (timeout_running) {
- SCH_RemoveTimeout(timeout_id);
- timeout_running = 0;
- }
+ SCH_RemoveTimeout(timeout_id);
+ timeout_id = 0;
/* Remove input file handler */
if (fd >= 0) {
static void
measurement_timeout(void *any)
{
- timeout_running = 0;
+ timeout_id = 0;
switch_interrupts(1);
}
switch_interrupts(0);
- timeout_running = 1;
timeout_id = SCH_AddTimeoutByDelay((double) measurement_period, measurement_timeout, NULL);
}
switch_interrupts(0);
- timeout_running = 1;
timeout_id = SCH_AddTimeoutByDelay((double) measurement_period, measurement_timeout, NULL);
}
case OM_NORMAL:
switch_interrupts(0);
- timeout_running = 1;
timeout_id = SCH_AddTimeoutByDelay((double) measurement_period, measurement_timeout, NULL);
break;
after_init_hook_arg = anything;
operating_mode = OM_INITIAL;
- timeout_running = 0;
+ timeout_id = 0;
switch_interrupts(1);
-
}
/* ================================================== */
void
RTC_Linux_StartMeasurements(void)
{
- timeout_running = 0;
measurement_timeout(NULL);
}
coef_ref_time = now.tv_sec;
/* And start rapid sampling, interrupts on now */
- if (timeout_running) {
- SCH_RemoveTimeout(timeout_id);
- timeout_running = 0;
- }
+ SCH_RemoveTimeout(timeout_id);
+ timeout_id = 0;
switch_interrupts(1);
}
/* ================================================== */
+static SCH_TimeoutID
+get_new_tqe_id(void)
+{
+ next_tqe_id++;
+ if (!next_tqe_id)
+ next_tqe_id++;
+
+ return next_tqe_id;
+}
+
+/* ================================================== */
+
SCH_TimeoutID
SCH_AddTimeout(struct timeval *tv, SCH_TimeoutHandler handler, SCH_ArbitraryArgument arg)
{
new_tqe = allocate_tqe();
- new_tqe->id = next_tqe_id++;
+ new_tqe->id = get_new_tqe_id();
new_tqe->handler = handler;
new_tqe->arg = arg;
new_tqe->tv = *tv;
/* We have located the insertion point */
new_tqe = allocate_tqe();
- new_tqe->id = next_tqe_id++;
+ new_tqe->id = get_new_tqe_id();
new_tqe->handler = handler;
new_tqe->arg = arg;
UTI_AddDoubleToTimeval(&now, new_min_delay, &new_tqe->tv);
assert(initialised);
+ if (!id)
+ return;
+
for (ptr = timer_queue.next; ptr != &timer_queue; ptr = ptr->next) {
if (ptr->id == id) {
#include "sysincl.h"
+/* Type for timeout IDs, valid IDs are always greater than zero */
typedef unsigned long SCH_TimeoutID;
typedef enum {
#define MIN_SLEW_TIMEOUT 1.0
#define MAX_SLEW_TIMEOUT 1.0e4
-/* Scheduler timeout ID and flag if the timer is currently running */
+/* Scheduler timeout ID for ending of the currently running slew */
static SCH_TimeoutID slew_timeout_id;
-static int slew_timer_running;
/* Suggested offset correction rate (correction time * offset) */
static double correction_rate;
double old_slew_freq, total_freq, corr_freq, duration;
/* Remove currently running timeout */
- if (slew_timer_running)
- SCH_RemoveTimeout(slew_timeout_id);
+ SCH_RemoveTimeout(slew_timeout_id);
LCL_ReadRawTime(&now);
/* Restart timer for the next update */
UTI_AddDoubleToTimeval(&now, duration, &end_of_slew);
slew_timeout_id = SCH_AddTimeout(&end_of_slew, handle_end_of_slew, NULL);
-
slew_start = now;
- slew_timer_running = 1;
DEBUG_LOG(LOGF_SysGeneric, "slew offset=%e corr_rate=%e base_freq=%f total_freq=%f slew_freq=%e duration=%f slew_error=%e",
offset_register, correction_rate, base_freq, total_freq, slew_freq,
static void
handle_end_of_slew(void *anything)
{
- slew_timer_running = 0;
+ slew_timeout_id = 0;
update_slew();
}
/* Must *NOT* leave a slew running - clock could drift way off
if the daemon is not restarted */
- if (slew_timer_running) {
- SCH_RemoveTimeout(slew_timeout_id);
- slew_timer_running = 0;
- }
+
+ SCH_RemoveTimeout(slew_timeout_id);
+ slew_timeout_id = 0;
(*drv_set_freq)(clamp_freq(base_freq));
/* Cancel systematic drift */
-static int drift_removal_running = 0;
static SCH_TimeoutID drift_removal_id;
/* ================================================== */
drift_removal_id = SCH_AddTimeoutByDelay(drift_removal_interval, drift_removal_timeout, NULL);
- drift_removal_running = 1;
}
/* ================================================== */
void
SYS_MacOSX_Finalise(void)
{
- if (drift_removal_running) {
- SCH_RemoveTimeout(drift_removal_id);
- }
+ SCH_RemoveTimeout(drift_removal_id);
clock_finalise();
}