From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Thu, 28 Oct 2021 15:09:17 +0000 (+0100) Subject: Add infrastructure for executing timed tasks, with a simple example. X-Git-Tag: 1.2~102 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b691e48134093232eac7feaea41054a3337cc90c;p=thirdparty%2Fnqptp.git Add infrastructure for executing timed tasks, with a simple example. --- diff --git a/nqptp-clock-sources.c b/nqptp-clock-sources.c index bf81283..c894300 100644 --- a/nqptp-clock-sources.c +++ b/nqptp-clock-sources.c @@ -338,17 +338,17 @@ void update_master() { update_master_clock_info(0, NULL, 0, 0, 0); } if (timing_peer_count == 0) - debug(2, "No timing peer list found"); + debug(2, "no valid qualified clocks "); else - debug(1, "No master clock not found!"); + debug(1, "no master clock!"); } else { // we found a master clock if (old_master != best_so_far) { - // if the naster is a new one + // if the master is a new one clocks_private[best_so_far].flags |= (1 << clock_is_becoming_master); } else { - // if its the same one as before + // if it's the same one as before clocks_private[best_so_far].flags |= (1 << clock_is_master); } } diff --git a/nqptp.c b/nqptp.c index e067e99..6870119 100644 --- a/nqptp.c +++ b/nqptp.c @@ -62,6 +62,24 @@ sockets_open_bundle sockets_open_stuff; int master_clock_index = -1; +typedef struct { + uint64_t trigger_time; + uint64_t (*task)(uint64_t nominal_call_time, void * private_data); +} timed_task_t; + +#define TIMED_TASKS 2 + +timed_task_t timed_tasks[TIMED_TASKS]; + + +uint64_t sample_task(uint64_t call_time, void *private_data) { + int *i = (int *)private_data; + debug(1,"sample_task %d called.", *i); + uint64_t next_time = call_time; + next_time = next_time + 1000000000; + return next_time; +} + struct shm_structure *shared_memory = NULL; // this is where public clock info is available int epoll_fd; @@ -237,6 +255,13 @@ int main(int argc, char **argv) { if (err != 0) { die("mutex initialization failed - %s.", strerror(errno)); } + + // start the timed tasks + + timed_tasks[0].trigger_time = get_time_now() + 1000000000; + timed_tasks[0].task = sample_task; + timed_tasks[1].trigger_time = get_time_now() + 10000000000; + timed_tasks[1].task = sample_task; // now, get down to business if (sockets_open_stuff.sockets_open > 0) { @@ -374,6 +399,16 @@ int main(int argc, char **argv) { } if (retval >= 0) manage_clock_sources(reception_time, (clock_source_private_data *)&clocks_private); + int i; + for (i = 0; i