1/*
2 * Layer Two Tunnelling Protocol Daemon
3 * Copyright (C) 1998 Adtran, Inc.
4 * Copyright (C) 2002 Jeff McAdams
5 *
6 * Mark Spencer
7 *
8 * This software is distributed under the terms
9 * of the GPL, which you should have received
10 * along with this source.
11 *
12 * Scheduler structures and functions
13 *
14 */
15
16#ifndef _SCHEDULER_H
17#define _SCHEDULER_H
18#include <sys/time.h>
19
20/*
21 * The idea is to provide a general scheduler which can schedule
22 * events to be run periodically
23 */
24
25struct schedule_entry
26{
27    struct timeval tv;          /* Scheduled time to execute */
28    void (*func) (void *);      /* Function to execute */
29    void *data;                 /* Data to be passed to func */
30    struct schedule_entry *next;        /* Next entry in queue */
31};
32
33extern struct schedule_entry *events;
34
35/* Schedule func to be executed with argument data sometime
36   tv in the future. */
37
38struct schedule_entry *schedule (struct timeval tv, void (*func) (void *),
39                                 void *data);
40
41/* Like schedule() but tv represents an absolute time in the future */
42
43struct schedule_entry *aschedule (struct timeval tv, void (*func) (void *),
44                                  void *data);
45
46/* Remove a scheduled event from the queue */
47
48void deschedule (struct schedule_entry *);
49
50/* The alarm handler */
51
52void alarm_handler (int);
53
54/* Initialization function */
55void init_scheduler (void);
56
57/* Prevent the scheduler from running */
58void schedule_lock ();
59
60/* Restore normal scheduling functions */
61void schedule_unlock ();
62
63/* Compare two timeval functions and see if a <= b */
64
65#define TVLESS(a,b) ((a).tv_sec == (b).tv_sec ? \
66				((a).tv_usec < (b).tv_usec) : \
67				((a).tv_sec < (b).tv_sec))
68#define TVLESSEQ(a,b) ((a).tv_sec == (b).tv_sec ? \
69				((a).tv_usec <= (b).tv_usec) : \
70				((a).tv_sec <= (b).tv_sec))
71#define TVGT(a,b) ((a).tv_sec == (b).tv_sec ? \
72				((a).tv_usec > (b).tv_usec) : \
73				((a).tv_sec > (b).tv_sec))
74#endif
75