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