Skip to content

Commit

Permalink
sched: add function to remove all timers and descriptors
Browse files Browse the repository at this point in the history
This allows a helper process to be started in an *_Initialise() call
and use the scheduler (unlike the privops helper, which has its own
loop).
  • Loading branch information
mlichvar committed Mar 5, 2020
1 parent 24538fe commit 26a1ed8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,20 @@ SCH_RemoveTimeout(SCH_TimeoutID id)
assert(0);
}

/* ================================================== */

void
SCH_Reset(void)
{
while (n_timer_queue_entries > 0)
SCH_RemoveTimeout(timer_queue.next->id);

while (one_highest_fd > 0) {
close(one_highest_fd - 1);
SCH_RemoveFileHandler(one_highest_fd - 1);
}
}

/* ================================================== */
/* Try to dispatch any timeouts that have already gone by, and
keep going until all are done. (The earlier ones may take so
Expand Down
3 changes: 3 additions & 0 deletions sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ extern SCH_TimeoutID SCH_AddTimeoutInClass(double min_delay, double separation,
/* The next one probably ought to return a status code */
extern void SCH_RemoveTimeout(SCH_TimeoutID);

/* Remove all timeouts and close all file descriptors */
extern void SCH_Reset(void);

extern void SCH_MainLoop(void);

extern void SCH_QuitProgram(void);
Expand Down

0 comments on commit 26a1ed8

Please sign in to comment.