24 #ifndef _ASTERISK_SCHED_H 25 #define _ASTERISK_SCHED_H 27 #if defined(__cplusplus) || defined(c_plusplus) 46 #define AST_SCHED_DEL(sched, id) \ 49 int _sched_res = -1; \ 50 while (id > -1 && (_sched_res = ast_sched_del(sched, id)) && ++_count < 10) \ 53 ast_debug(3, "Unable to cancel schedule ID %d.\n", id); \ 59 #define AST_SCHED_DEL_ACCESSOR(sched, obj, getter, setter) \ 62 int _sched_res = -1; \ 63 while (getter(obj) > -1 && (_sched_res = ast_sched_del(sched, getter(obj))) && ++_count < 10) \ 66 ast_debug(3, "Unable to cancel schedule ID %d.\n", getter(obj)); \ 80 #define AST_SCHED_DEL_UNREF(sched, id, refcall) \ 82 int _count = 0, _id; \ 83 while ((_id = id) > -1 && ast_sched_del(sched, _id) && ++_count < 10) { \ 87 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__); \ 88 } else if (_id > -1) { \ 98 #define AST_SCHED_DEL_SPINLOCK(sched, id, lock) \ 101 int _sched_res = -1; \ 102 while (id > -1 && (_sched_res = ast_sched_del(sched, id)) && ++_count < 10) { \ 103 ast_mutex_unlock(lock); \ 105 ast_mutex_lock(lock); \ 107 if (_count == 10) { \ 108 ast_debug(3, "Unable to cancel schedule ID %d.\n", id); \ 114 #define AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, variable) \ 117 while (id > -1 && ast_sched_del(sched, id) && ++_count < 10) { \ 121 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__); \ 122 id = ast_sched_add_variable(sched, when, callback, data, variable); \ 125 #define AST_SCHED_REPLACE(id, sched, when, callback, data) \ 126 AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, 0) 132 #define AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, variable, unrefcall, addfailcall, refcall) \ 134 int _count = 0, _res=1; \ 135 void *_data = (void *)ast_sched_find_data(sched, id); \ 136 while (id > -1 && (_res = ast_sched_del(sched, id) && _count++ < 10)) { \ 139 if (!_res && _data && _data != data) \ 142 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__); \ 145 id = ast_sched_add_variable(sched, when, callback, data, variable); \ 150 #define AST_SCHED_REPLACE_UNREF(id, sched, when, callback, data, unrefcall, addfailcall, refcall) \ 151 AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, 0, unrefcall, addfailcall, refcall) 176 #define AST_SCHED_CB(a) ((ast_sched_cb)(a)) 343 #define ast_sched_add_object(obj,con,when,callback) ast_sched_add((con),(when),(callback), ASTOBJ_REF((obj))) 349 #define ast_sched_del_object(obj,destructor,con,id) do { \ 351 ast_sched_del((con),(id)); \ 353 ASTOBJ_UNREF((obj),(destructor)); \ 367 #if defined(__cplusplus) || defined(c_plusplus)
int ast_sched_start_thread(struct ast_sched_context *con)
Start a thread for processing scheduler entries.
void ast_sched_clean_by_callback(struct ast_sched_context *con, ast_sched_cb match, ast_sched_cb cleanup_cb)
Clean all scheduled events with matching callback.
int ast_sched_runq(struct ast_sched_context *con)
Runs the queue.
int ast_sched_add_variable(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result
Adds a scheduled event with rescheduling support.
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
static int cleanup_cb(void *obj, void *arg, int flags)
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
void ast_sched_report(struct ast_sched_context *con, struct ast_str **buf, struct ast_cb_names *cbnames)
Show statics on what it is in the schedule queue.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
long ast_sched_when(struct ast_sched_context *con, int id)
Returns the number of seconds before an event takes place.
#define attribute_warn_unused_result
int ast_sched_del(struct ast_sched_context *con, int id) attribute_warn_unused_result
Deletes a scheduled event.
const void * ast_sched_find_data(struct ast_sched_context *con, int id)
Find a sched structure and return the data field associated with it.
int(* ast_sched_cb)(const void *data)
scheduler callback
int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
Adds a scheduled event.
int ast_sched_replace_variable(int old_id, struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result
replace a scheduler entry
int ast_sched_replace(int old_id, struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
replace a scheduler entry
void ast_sched_dump(struct ast_sched_context *con)
Dumps the scheduler contents.
int ast_sched_wait(struct ast_sched_context *con) attribute_warn_unused_result
Determines number of seconds until the next outstanding event to take place.
void ast_sched_context_destroy(struct ast_sched_context *c)
destroys a schedule context