00001 /*
00002 * Asterisk
00003 *
00004 * Mark Spencer <markster@marko.net>
00005 *
00006 * Copyright(C) Mark Spencer
00007 *
00008 * Distributed under the terms of the GNU General Public License (GPL) Version 2
00009 *
00010 * Scheduler Routines (derived from cheops)
00011 *
00012 */
00013
00014 #ifndef _ASTERISK_SCHED_H
00015 #define _ASTERISK_SCHED_H
00016
00017 #if defined(__cplusplus) || defined(c_plusplus)
00018 extern "C" {
00019 #endif
00020
00021 //! Max num of schedule structs
00022 /*!
00023 * The max number of schedule structs to keep around
00024 * for use. Undefine to disable schedule structure
00025 * caching. (Only disable this on very low memory
00026 * machines)
00027 */
00028 #define SCHED_MAX_CACHE 128
00029
00030 struct sched_context;
00031
00032 //! New schedule context
00033 /* !
00034 * Create a scheduling context
00035 * Returns a malloc'd sched_context structure, NULL on failure
00036 */
00037 extern struct sched_context *sched_context_create(void);
00038
00039 //! destroys a schedule context
00040 /*!
00041 * \param c Context to free
00042 * Destroys (free's) the given sched_context structure
00043 * Returns 0 on success, -1 on failure
00044 */
00045 void sched_context_destroy(struct sched_context *c);
00046
00047 //! callback for a cheops scheduler
00048 /*!
00049 * A cheops scheduler callback takes a pointer with callback data and
00050 * returns a 0 if it should not be run again, or non-zero if it should be
00051 * rescheduled to run again
00052 */
00053 typedef int (*ast_sched_cb)(void *data);
00054 #define AST_SCHED_CB(a) ((ast_sched_cb)(a))
00055
00056 //!Adds a scheduled event
00057 /*!
00058 * \param con Schduler context to add
00059 * \param when how many milliseconds to wait for event to occur
00060 * \param callback function to call when the amount of time expires
00061 * \param data data to pass to the callback
00062 * Schedule an event to take place at some point in the future. callback
00063 * will be called with data as the argument, when milliseconds into the
00064 * future (approximately)
00065 * Returns 0 on success, -1 on failure
00066 */
00067 extern int ast_sched_add(struct sched_context *con, int when, ast_sched_cb callback, void *data);
00068
00069 //! Deletes a scheduled event
00070 /*!
00071 * \param con scheduling context to delete item from
00072 * \param id ID of the scheduled item to delete
00073 * Remove this event from being run. A procedure should not remove its
00074 * own event, but return 0 instead.
00075 * Returns 0 on success, -1 on failure
00076 */
00077 extern int ast_sched_del(struct sched_context *con, int id);
00078
00079 //! Determines number of seconds until the next outstanding event to take place
00080 /*!
00081 * \param con context to act upon
00082 * Determine the number of seconds until the next outstanding event
00083 * should take place, and return the number of milliseconds until
00084 * it needs to be run. This value is perfect for passing to the poll
00085 * call. Returns "-1" if there is nothing there are no scheduled events
00086 * (and thus the poll should not timeout)
00087 */
00088 extern int ast_sched_wait(struct sched_context *con);
00089
00090 //! Runs the queue
00091 /*!
00092 * \param con Scheduling context to run
00093 * Run the queue, executing all callbacks which need to be performed
00094 * at this time. Returns the number of events processed.
00095 */
00096 extern int ast_sched_runq(struct sched_context *con);
00097
00098 //!Dumps the scheduler contents
00099 /*!
00100 * \param con Context to dump
00101 * Debugging: Dump the contents of the scheduler to stderr
00102 */
00103 extern void ast_sched_dump(struct sched_context *con);
00104
00105 #if defined(__cplusplus) || defined(c_plusplus)
00106 }
00107 #endif
00108
00109
00110
00111 #endif
1.2.15