23 #ifndef _ASTERISK_SCHED_H
24 #define _ASTERISK_SCHED_H
26 #if defined(__cplusplus) || defined(c_plusplus)
37 #define SCHED_MAX_CACHE 128
51 #define AST_SCHED_DEL(sched, id) \
54 int _sched_res = -1; \
55 while (id > -1 && (_sched_res = ast_sched_del(sched, id)) && ++_count < 10) \
57 if (_count == 10 && option_debug > 2) { \
58 ast_log(LOG_DEBUG, "Unable to cancel schedule ID %d.\n", id); \
69 #define AST_SCHED_DEL_UNREF(sched, id, refcall) \
72 while (id > -1 && ast_sched_del(sched, id) && ++_count < 10) { \
76 ast_log(LOG_WARNING, "Unable to cancel schedule ID %d. This is probably a bug (%s: %s, line %d).\n", id, __FILE__, __PRETTY_FUNCTION__, __LINE__); \
86 #define AST_SCHED_DEL_SPINLOCK(sched, id, lock) \
89 int _sched_res = -1; \
90 while (id > -1 && (_sched_res = ast_sched_del(sched, id)) && ++_count < 10) { \
91 ast_mutex_unlock(lock); \
93 ast_mutex_lock(lock); \
95 if (_count == 10 && option_debug > 2) { \
96 ast_log(LOG_DEBUG, "Unable to cancel schedule ID %d.\n", id); \
102 #define AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, variable) \
105 while (id > -1 && ast_sched_del(sched, id) && ++_count < 10) { \
109 ast_log(LOG_WARNING, "Unable to cancel schedule ID %d. This is probably a bug (%s: %s, line %d).\n", id, __FILE__, __PRETTY_FUNCTION__, __LINE__); \
110 id = ast_sched_add_variable(sched, when, callback, data, variable); \
113 #define AST_SCHED_REPLACE(id, sched, when, callback, data) \
114 AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, 0)
120 #define AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, variable, unrefcall, addfailcall, refcall) \
122 int _count = 0, _res=1; \
123 void *_data = (void *)ast_sched_find_data(sched, id); \
124 while (id > -1 && (_res = ast_sched_del(sched, id) && _count++ < 10)) { \
127 if (!_res && _data) \
130 ast_log(LOG_WARNING, "Unable to cancel schedule ID %d. This is probably a bug (%s: %s, line %d).\n", id, __FILE__, __PRETTY_FUNCTION__, __LINE__); \
132 id = ast_sched_add_variable(sched, when, callback, data, variable); \
137 #define AST_SCHED_REPLACE_UNREF(id, sched, when, callback, data, unrefcall, addfailcall, refcall) \
138 AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, 0, unrefcall, addfailcall, refcall)
161 #define AST_SCHED_CB(a) ((ast_sched_cb)(a))
255 int _ast_sched_del(
struct sched_context *con,
int id,
const char *file,
int line,
const char *
function) attribute_warn_unused_result;
256 #define ast_sched_del(a, b) _ast_sched_del(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)
295 #define ast_sched_add_object(obj,con,when,callback) ast_sched_add((con),(when),(callback), ASTOBJ_REF((obj)))
301 #define ast_sched_del_object(obj,destructor,con,id) do { \
303 ast_sched_del((con),(id)); \
305 ASTOBJ_UNREF((obj),(destructor)); \
376 const void *data,
int variable);
403 #define ast_sched_thread_del(st, id) ({ \
404 struct sched_context *__tmp_context = ast_sched_thread_get_context(st); \
405 AST_SCHED_DEL(__tmp_context, id); \
417 #if defined(__cplusplus) || defined(c_plusplus)
int ast_sched_del(struct sched_context *con, int id) attribute_warn_unused_result
Deletes a scheduled event Remove this event from being run. A procedure should not remove its own eve...
struct ast_sched_thread * ast_sched_thread_destroy(struct ast_sched_thread *st)
Destroy a scheduler and its thread.
struct ast_sched_thread * ast_sched_thread_create(void)
Create a scheduler with a dedicated thread.
int ast_sched_thread_add_variable(struct ast_sched_thread *st, int when, ast_sched_cb cb, const void *data, int variable)
Add a variable reschedule time scheduler entry.
int ast_sched_add_variable(struct sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result
Schedule callback(data) to happen when ms into the future.
int ast_sched_add(struct sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
Adds a scheduled event Schedule an event to take place at some point in the future. callback will be called with data as the argument, when milliseconds into the future (approximately) If callback returns 0, no further events will be re-scheduled.
void ast_sched_dump(struct sched_context *con)
Dumps the scheduler contents Debugging: Dump the contents of the scheduler to stderr.
void ast_sched_report(struct sched_context *con, struct ast_str **buf, struct ast_cb_names *cbnames)
Show statics on what it is in the schedule queue.
int ast_sched_replace(int old_id, struct sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
replace a scheduler entry
const void * ast_sched_find_data(struct sched_context *con, int id)
Find a sched structure and return the data field associated with it.
void sched_context_destroy(struct sched_context *c)
destroys a schedule context Destroys (free's) the given sched_context structure
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
long ast_sched_when(struct sched_context *con, int id)
Returns the number of seconds before an event takes place.
int ast_sched_replace_variable(int old_id, struct sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result
replace a scheduler entry
struct sched_context * ast_sched_thread_get_context(struct ast_sched_thread *st)
Get the scheduler context for a given ast_sched_thread.
#define attribute_warn_unused_result
void ast_sched_thread_poke(struct ast_sched_thread *st)
Force re-processing of the scheduler context.
int ast_sched_runq(struct sched_context *con)
Runs the queue.
struct sched_context * sched_context_create(void)
New schedule context.
int ast_sched_wait(struct sched_context *con) attribute_warn_unused_result
Determines number of seconds until the next outstanding event to take place Determine the number of s...
int(* ast_sched_cb)(const void *data)
callback for a cheops scheduler A cheops scheduler callback takes a pointer with callback data and ...
int ast_sched_thread_add(struct ast_sched_thread *st, int when, ast_sched_cb cb, const void *data)
Add a scheduler entry.