Version 0.1.1 from FTP
[asterisk/asterisk.git] / include / asterisk / sched.h
1 /*
2  * Asterisk
3  * 
4  * Mark Spencer <markster@marko.net>
5  *
6  * Copyright(C) Mark Spencer
7  * 
8  * Distributed under the terms of the GNU General Public License (GPL) Version 2
9  *
10  * Scheduler Routines (derived from cheops)
11  *
12  */
13
14 #ifndef _ASTERISK_SCHED_H
15 #define _ASTERISK_SCHED_H
16
17 #if defined(__cplusplus) || defined(c_plusplus)
18 extern "C" {
19 #endif
20
21 /*
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 
25  * machines)
26  */
27  
28 #define SCHED_MAX_CACHE 128
29
30 struct sched_context;
31
32 /* Create a scheduling context */
33 extern struct sched_context *sched_context_create(void);
34
35 void sched_context_destroy(struct sched_context *);
36
37 /* 
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
41  */
42 typedef int (*ast_sched_cb)(void *data);
43 #define AST_SCHED_CB(a) ((ast_sched_cb)(a))
44
45 /* 
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)
49  */
50 extern int ast_sched_add(struct sched_context *con, int when, ast_sched_cb callback, void *data);
51
52 /*
53  * Remove this event from being run.  A procedure should not remove its
54  * own event, but return 0 instead.
55  */
56 extern int ast_sched_del(struct sched_context *con, int id);
57
58 /*
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)
64  */
65 extern int ast_sched_wait(struct sched_context *con);
66
67 /*
68  * Run the queue, executing all callbacks which need to be performed
69  * at this time.  Returns the number of events processed.
70  */
71 extern int ast_sched_runq(struct sched_context *con);
72
73 /*
74  * Debugging: Dump the contents of the scheduler to stderr
75  */
76 extern void ast_sched_dump(struct sched_context *con);
77
78 #if defined(__cplusplus) || defined(c_plusplus)
79 }
80 #endif
81
82
83
84 #endif