4 * Mark Spencer <markster@marko.net>
6 * Copyright(C) Mark Spencer
8 * Distributed under the terms of the GNU General Public License (GPL) Version 2
10 * Scheduler Routines (derived from cheops)
14 #ifndef _ASTERISK_SCHED_H
15 #define _ASTERISK_SCHED_H
17 #if defined(__cplusplus) || defined(c_plusplus)
22 * The max number of schedule structs to keep around
23 * for use. Undefine to disable schedule structure
24 * caching. (Only disable this on very low memory
28 #define SCHED_MAX_CACHE 128
32 /* Create a scheduling context */
33 extern struct sched_context *sched_context_create(void);
35 void sched_context_destroy(struct sched_context *);
38 * A cheops scheduler callback takes a pointer with callback data and
39 * returns a 0 if it should not be run again, or non-zero if it should be
40 * rescheduled to run again
42 typedef int (*ast_sched_cb)(void *data);
43 #define AST_SCHED_CB(a) ((ast_sched_cb)(a))
46 * Schedule an event to take place at some point in the future. callback
47 * will be called with data as the argument, when milliseconds into the
48 * future (approximately)
50 extern int ast_sched_add(struct sched_context *con, int when, ast_sched_cb callback, void *data);
53 * Remove this event from being run. A procedure should not remove its
54 * own event, but return 0 instead.
56 extern int ast_sched_del(struct sched_context *con, int id);
59 * Determine the number of seconds until the next outstanding event
60 * should take place, and return the number of milliseconds until
61 * it needs to be run. This value is perfect for passing to the poll
62 * call. Returns "-1" if there is nothing there are no scheduled events
63 * (and thus the poll should not timeout)
65 extern int ast_sched_wait(struct sched_context *con);
68 * Run the queue, executing all callbacks which need to be performed
69 * at this time. Returns the number of events processed.
71 extern int ast_sched_runq(struct sched_context *con);
74 * Debugging: Dump the contents of the scheduler to stderr
76 extern void ast_sched_dump(struct sched_context *con);
78 #if defined(__cplusplus) || defined(c_plusplus)