Scheduler Routines (derived from cheops) More...
Go to the source code of this file.
Data Structures | |
struct | ast_cb_names |
Macros | |
#define | ast_sched_add_object(obj, con, when, callback) ast_sched_add((con),(when),(callback), ASTOBJ_REF((obj))) |
Convenience macro for objects and reference (add) More... | |
#define | AST_SCHED_CB(a) ((ast_sched_cb)(a)) |
#define | AST_SCHED_DEL(sched, id) |
a loop construct to ensure that the scheduled task get deleted. The idea is that if we loop attempting to remove the scheduled task, then whatever callback had been running will complete and reinsert the task into the scheduler. More... | |
#define | ast_sched_del_object(obj, destructor, con, id) |
Convenience macro for objects and reference (del) More... | |
#define | AST_SCHED_DEL_SPINLOCK(sched, id, lock) |
schedule task to get deleted releasing the lock between attempts More... | |
#define | AST_SCHED_DEL_UNREF(sched, id, refcall) |
schedule task to get deleted and call unref function More... | |
#define | AST_SCHED_REPLACE(id, sched, when, callback, data) AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, 0) |
#define | AST_SCHED_REPLACE_UNREF(id, sched, when, callback, data, unrefcall, addfailcall, refcall) AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, 0, unrefcall, addfailcall, refcall) |
#define | AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, variable) |
#define | AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, variable, unrefcall, addfailcall, refcall) |
#define | ast_sched_thread_del(st, id) |
Delete a scheduler entry. More... | |
#define | SCHED_MAX_CACHE 128 |
Max num of schedule structs. More... | |
Typedefs | |
typedef int(* | ast_sched_cb )(const void *data) |
callback for a cheops scheduler A cheops scheduler callback takes a pointer with callback data and More... | |
Functions | |
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. More... | |
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. More... | |
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 event, but return 0 instead. In most cases, you should not call this routine directly, but use the AST_SCHED_DEL() macro instead (especially if you don't intend to do something different when it returns failure). More... | |
void | ast_sched_dump (struct sched_context *con) |
Dumps the scheduler contents Debugging: Dump the contents of the scheduler to stderr. More... | |
const void * | ast_sched_find_data (struct sched_context *con, int id) |
Find a sched structure and return the data field associated with it. More... | |
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 More... | |
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 More... | |
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. More... | |
int | ast_sched_runq (struct sched_context *con) |
Runs the queue. More... | |
int | ast_sched_thread_add (struct ast_sched_thread *st, int when, ast_sched_cb cb, const void *data) |
Add a scheduler entry. More... | |
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. More... | |
struct ast_sched_thread * | ast_sched_thread_create (void) |
Create a scheduler with a dedicated thread. More... | |
struct ast_sched_thread * | ast_sched_thread_destroy (struct ast_sched_thread *st) |
Destroy a scheduler and its thread. More... | |
struct sched_context * | ast_sched_thread_get_context (struct ast_sched_thread *st) |
Get the scheduler context for a given ast_sched_thread. More... | |
void | ast_sched_thread_poke (struct ast_sched_thread *st) |
Force re-processing of the scheduler context. More... | |
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 seconds until the next outstanding event should take place, and return the number of milliseconds until it needs to be run. This value is perfect for passing to the poll call. More... | |
long | ast_sched_when (struct sched_context *con, int id) |
Returns the number of seconds before an event takes place. More... | |
struct sched_context * | sched_context_create (void) |
New schedule context. More... | |
void | sched_context_destroy (struct sched_context *c) |
destroys a schedule context Destroys (free's) the given sched_context structure More... | |
Scheduler Routines (derived from cheops)
Definition in file sched.h.
#define ast_sched_add_object | ( | obj, | |
con, | |||
when, | |||
callback | |||
) | ast_sched_add((con),(when),(callback), ASTOBJ_REF((obj))) |
#define AST_SCHED_CB | ( | a | ) | ((ast_sched_cb)(a)) |
a loop construct to ensure that the scheduled task get deleted. The idea is that if we loop attempting to remove the scheduled task, then whatever callback had been running will complete and reinsert the task into the scheduler.
Since macro expansion essentially works like pass-by-name parameter passing, this macro will still work correctly even if the id of the task to delete changes. This holds as long as the name of the id which could change is passed to the macro and not a copy of the value of the id.
Definition at line 51 of file sched.h.
Referenced by __oh323_destroy(), __oh323_update_info(), __sip_reliable_xmit(), __sip_semi_ack(), ack_trans(), ast_rtp_destroy(), ast_rtp_stop(), ast_sched_replace(), ast_sched_replace_variable(), build_gateway(), build_peer(), destroy_packet(), destroy_packets(), destroy_peer(), destroy_trans(), dialog_unlink_all(), dnsmgr_start_refresh(), do_reload(), esc_entry_destructor(), filestream_close(), handle_command_response(), handle_request_cancel(), handle_sip_publish_remove(), mgcpsock_read(), misdn_tasks_remove(), qualify_peer(), receive_digit(), sip_cc_agent_stop_offer_timer(), sip_cc_monitor_cancel_available_timer(), sip_registry_destroy(), sip_send_all_mwi_subscriptions(), sip_subscribe_mwi_destroy(), and submit_unscheduled_batch().
#define ast_sched_del_object | ( | obj, | |
destructor, | |||
con, | |||
id | |||
) |
schedule task to get deleted releasing the lock between attempts
Definition at line 86 of file sched.h.
Referenced by iax2_destroy_helper().
schedule task to get deleted and call unref function
Definition at line 69 of file sched.h.
Referenced by build_peer(), cleanup_all_regs(), dialog_unlink_all(), handle_request_bye(), handle_request_invite(), handle_response_invite(), handle_response_register(), interpret_t38_parameters(), parse_register_contact(), peer_sched_cleanup(), restart_session_timer(), send_response(), sip_cancel_destroy(), sip_hangup(), sip_poke_peer(), sip_unregister(), start_session_timer(), stop_session_timer(), and update_provisional_keepalive().
#define AST_SCHED_REPLACE | ( | id, | |
sched, | |||
when, | |||
callback, | |||
data | |||
) | AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, 0) |
Definition at line 113 of file sched.h.
Referenced by schedule_calendar_event().
#define AST_SCHED_REPLACE_UNREF | ( | id, | |
sched, | |||
when, | |||
callback, | |||
data, | |||
unrefcall, | |||
addfailcall, | |||
refcall | |||
) | AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, 0, unrefcall, addfailcall, refcall) |
Definition at line 137 of file sched.h.
Referenced by handle_response_peerpoke(), handle_response_register(), handle_sip_publish_modify(), handle_sip_publish_refresh(), realtime_peer(), reg_source_db(), sip_call(), sip_poke_all_peers(), sip_poke_noanswer(), sip_poke_peer(), sip_send_all_registers(), and transmit_register().
Definition at line 102 of file sched.h.
Referenced by __sip_reliable_xmit().
#define ast_sched_thread_del | ( | st, | |
id | |||
) |
Delete a scheduler entry.
This uses the AST_SCHED_DEL macro internally.
st | the handle to the scheduler and thread |
id | scheduler entry id to delete |
0 | success |
non-zero | failure |
Definition at line 403 of file sched.h.
Referenced by build_peer(), cc_generic_agent_stop_offer_timer(), cc_generic_monitor_cancel_available_timer(), delete_users(), iax2_destroy_helper(), iax2_frame_free(), iax2_poke_peer(), iax2_sched_replace(), make_trunk(), realtime_peer(), reg_source_db(), schedule_delivery(), socket_process(), unlink_peer(), and update_registry().
#define SCHED_MAX_CACHE 128 |
Max num of schedule structs.
Definition at line 37 of file sched.h.
Referenced by sched_release().
typedef int(* ast_sched_cb)(const void *data) |
int ast_sched_add | ( | struct sched_context * | con, |
int | when, | ||
ast_sched_cb | callback, | ||
const void * | data | ||
) |
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.
con | Scheduler context to add |
when | how many milliseconds to wait for event to occur |
callback | function to call when the amount of time expires |
data | data to pass to the callback |
Definition at line 446 of file sched.c.
References ast_sched_add_variable().
Referenced by __oh323_update_info(), ast_readaudio_callback(), ast_readvideo_callback(), ast_rtp_raw_write(), ast_rtp_read(), ast_sched_replace(), ast_sched_thread_add(), build_peer(), create_esc_entry(), do_register(), do_reload(), dundi_discover(), dundi_query(), dundi_send(), handle_command_response(), handle_request_invite(), handle_response_invite(), handle_response_subscribe(), mgcp_postrequest(), network_change_event_cb(), parse_register_contact(), populate_addr(), precache_trans(), qualify_peer(), receive_digit(), rtp_red_init(), sip_cc_agent_start_offer_timer(), sip_cc_monitor_request_cc(), sip_hangup(), sip_scheddestroy(), sip_send_all_mwi_subscriptions(), start_session_timer(), submit_scheduled_batch(), submit_unscheduled_batch(), transmit_register(), and update_provisional_keepalive().
int ast_sched_add_variable | ( | struct sched_context * | con, |
int | when, | ||
ast_sched_cb | callback, | ||
const void * | data, | ||
int | variable | ||
) |
Schedule callback(data) to happen when ms into the future.
Adds a scheduled event with rescheduling support
con | Scheduler context to add |
when | how many milliseconds to wait for event to occur |
callback | function to call when the amount of time expires |
data | data to pass to the callback |
variable | If true, the result value of callback function will be used for rescheduling 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 |
Definition at line 406 of file sched.c.
References ast_debug, ast_mutex_lock, ast_mutex_unlock, ast_sched_dump(), ast_tv(), sched::callback, sched::data, DEBUG, sched_context::eventcnt, sched::id, sched_context::lock, option_debug, sched::resched, sched_alloc(), sched_release(), sched_settime(), schedule(), sched::variable, and sched::when.
Referenced by _misdn_tasks_add_variable(), ast_sched_add(), ast_sched_replace_variable(), ast_sched_thread_add_variable(), dnsmgr_start_refresh(), and do_reload().
int ast_sched_del | ( | struct sched_context * | con, |
int | id | ||
) |
Deletes a scheduled event Remove this event from being run. A procedure should not remove its own event, but return 0 instead. In most cases, you should not call this routine directly, but use the AST_SCHED_DEL() macro instead (especially if you don't intend to do something different when it returns failure).
con | scheduling context to delete item from |
id | ID of the scheduled item to delete |
Deletes a scheduled event Remove this event from being run. A procedure should not remove its own event, but return 0 instead. In most cases, you should not call this routine directly, but use the AST_SCHED_DEL() macro instead (especially if you don't intend to do something different when it returns failure).
Definition at line 468 of file sched.c.
References ast_assert, ast_debug, ast_hashtab_lookup(), ast_hashtab_remove_this_object(), ast_heap_remove(), ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_sched_dump(), ast_threadstorage_get(), DEBUG, sched::id, last_del_id, sched_context::lock, LOG_WARNING, option_debug, sched_context::sched_heap, sched_release(), sched_context::schedcnt, and sched_context::schedq_ht.
Referenced by __sip_ack(), ast_rtp_prop_set(), ast_rtp_stop(), and destroy_event().
void ast_sched_dump | ( | struct sched_context * | con | ) |
Dumps the scheduler contents Debugging: Dump the contents of the scheduler to stderr.
con | Context to dump |
Dumps the scheduler contents Debugging: Dump the contents of the scheduler to stderr.
Definition at line 565 of file sched.c.
References ast_debug, ast_heap_peek(), ast_heap_size(), ast_mutex_lock, ast_mutex_unlock, ast_tvnow(), ast_tvsub(), sched_context::eventcnt, sched_context::highwater, sched_context::lock, sched_context::sched_heap, sched_context::schedccnt, and sched_context::schedcnt.
Referenced by ast_sched_add_variable(), ast_sched_del(), handle_dump_sched(), sip_do_reload(), and unload_module().
const void* ast_sched_find_data | ( | struct sched_context * | con, |
int | id | ||
) |
Find a sched structure and return the data field associated with it.
con | scheduling context in which to search fro the matching id |
id | ID of the scheduled item to find |
Definition at line 451 of file sched.c.
References ast_hashtab_lookup(), sched::data, sched::id, and sched_context::schedq_ht.
int ast_sched_replace | ( | int | old_id, |
struct sched_context * | con, | ||
int | when, | ||
ast_sched_cb | callback, | ||
const void * | data | ||
) |
replace a scheduler entry
This deletes the scheduler entry for old_id if it exists, and then calls ast_sched_add to create a new entry. A negative old_id will be ignored.
-1 | failure |
otherwise,returns | scheduled item ID |
Definition at line 438 of file sched.c.
References ast_sched_add(), and AST_SCHED_DEL.
int ast_sched_replace_variable | ( | int | old_id, |
struct sched_context * | con, | ||
int | when, | ||
ast_sched_cb | callback, | ||
const void * | data, | ||
int | variable | ||
) |
replace a scheduler entry
This deletes the scheduler entry for old_id if it exists, and then calls ast_sched_add to create a new entry. A negative old_id will be ignored.
-1 | failure |
otherwise,returns | scheduled item ID |
Definition at line 394 of file sched.c.
References ast_sched_add_variable(), and AST_SCHED_DEL.
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.
con | Schedule context to check |
buf | dynamic string to store report |
cbnames | to check against |
Definition at line 527 of file sched.c.
References ast_heap_peek(), ast_heap_size(), ast_mutex_lock, ast_mutex_unlock, ast_str_append(), ast_str_set(), sched::callback, ast_cb_names::cblist, sched_context::highwater, ast_cb_names::list, sched_context::lock, ast_cb_names::numassocs, sched_context::sched_heap, and sched_context::schedcnt.
Referenced by sip_show_sched().
int ast_sched_runq | ( | struct sched_context * | con | ) |
Runs the queue.
con | Scheduling context to run Run the queue, executing all callbacks which need to be performed at this time. |
con | context to act upon |
Runs the queue.
Definition at line 600 of file sched.c.
References ast_debug, ast_hashtab_remove_this_object(), ast_heap_peek(), ast_heap_pop(), ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_tv(), ast_tvadd(), ast_tvcmp(), ast_tvnow(), sched::callback, sched::data, DEBUG, sched::id, sched_context::lock, LOG_ERROR, sched::resched, sched_context::sched_heap, sched_release(), sched_settime(), sched_context::schedcnt, sched_context::schedq_ht, schedule(), sched::variable, and sched::when.
Referenced by background_detect_exec(), dial_exec_full(), do_cdr(), do_monitor(), do_refresh(), handle_speechrecognize(), misdn_tasks_thread_func(), network_thread(), reload_config(), sched_run(), speech_background(), wait_for_winner(), and waitstream_core().
int ast_sched_thread_add | ( | struct ast_sched_thread * | st, |
int | when, | ||
ast_sched_cb | cb, | ||
const void * | data | ||
) |
Add a scheduler entry.
st | the handle to the scheduler and thread |
when | the number of ms in the future to run the task. A value <= 0 is treated as "run now". |
cb | the function to call when the scheduled time arrives |
data | the parameter to pass to the scheduler callback |
-1 | Failure |
>=0 | Sched ID of added task |
Definition at line 210 of file sched.c.
References ast_cond_signal, ast_mutex_lock, ast_mutex_unlock, ast_sched_add(), ast_sched_thread::cond, ast_sched_thread::context, and ast_sched_thread::lock.
Referenced by cc_generic_agent_start_offer_timer(), cc_generic_monitor_request_cc(), iax2_hangup(), iax2_key_rotate(), iax2_sched_add(), and iax2_sched_replace().
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.
st | the handle to the scheduler and thread |
when | the number of ms in the future to run the task. A value <= 0 is treated as "run now". |
cb | the function to call when the scheduled time arrives |
data | the parameter to pass to the scheduler callback |
variable | If this value is non-zero, then the scheduler will use the return value of the scheduler as the amount of time in the future to run the task again. Normally, a return value of 0 means do not re-schedule, and non-zero means re-schedule using the time provided when the scheduler entry was first created. |
-1 | Failure |
>=0 | Sched ID of added task |
Definition at line 195 of file sched.c.
References ast_cond_signal, ast_mutex_lock, ast_mutex_unlock, ast_sched_add_variable(), ast_sched_thread::cond, ast_sched_thread::context, and ast_sched_thread::lock.
Referenced by stun_start_monitor().
struct ast_sched_thread* ast_sched_thread_create | ( | void | ) |
Create a scheduler with a dedicated thread.
This function should be used to allocate a scheduler context and a dedicated thread for processing scheduler entries. The thread is started immediately.
NULL | error |
non-NULL | a handle to the scheduler and its dedicated thread. |
Definition at line 167 of file sched.c.
References ast_calloc, ast_cond_init, ast_log(), ast_mutex_init, ast_pthread_create_background, AST_PTHREADT_NULL, ast_sched_thread_destroy(), ast_sched_thread::cond, ast_sched_thread::context, ast_sched_thread::lock, LOG_ERROR, sched_context_create(), sched_run(), and ast_sched_thread::thread.
Referenced by ast_cc_init(), load_module(), and stun_start_monitor().
struct ast_sched_thread* ast_sched_thread_destroy | ( | struct ast_sched_thread * | st | ) |
Destroy a scheduler and its thread.
This function is used to destroy a scheduler context and the dedicated thread that was created for handling scheduler entries. Any entries in the scheduler that have not yet been processed will be thrown away. Once this function is called, the handle must not be used again.
st | the handle to the scheduler and thread |
Definition at line 143 of file sched.c.
References ast_cond_destroy, ast_cond_signal, ast_free, ast_mutex_destroy, ast_mutex_lock, ast_mutex_unlock, AST_PTHREADT_NULL, ast_sched_thread::cond, ast_sched_thread::context, ast_sched_thread::lock, sched_context_destroy(), ast_sched_thread::stop, and ast_sched_thread::thread.
Referenced by __unload_module(), ast_sched_thread_create(), cc_shutdown(), load_module(), stun_start_monitor(), and stun_stop_monitor().
struct sched_context* ast_sched_thread_get_context | ( | struct ast_sched_thread * | st | ) |
Get the scheduler context for a given ast_sched_thread.
This function should be used only when direct access to the scheduler context is required. Its use is discouraged unless necessary. The cases where this is currently required is when you want to take advantage of one of the AST_SCHED macros.
st | the handle to the scheduler and thread |
Definition at line 138 of file sched.c.
References ast_sched_thread::context.
Referenced by iax2_destroy_helper().
void ast_sched_thread_poke | ( | struct ast_sched_thread * | st | ) |
Force re-processing of the scheduler context.
st | the handle to the scheduler and thread |
Definition at line 131 of file sched.c.
References ast_cond_signal, ast_mutex_lock, ast_mutex_unlock, ast_sched_thread::cond, and ast_sched_thread::lock.
int ast_sched_wait | ( | struct sched_context * | con | ) |
Determines number of seconds until the next outstanding event to take place Determine the number of seconds until the next outstanding event should take place, and return the number of milliseconds until it needs to be run. This value is perfect for passing to the poll call.
con | context to act upon |
Determines number of seconds until the next outstanding event to take place Determine the number of seconds until the next outstanding event should take place, and return the number of milliseconds until it needs to be run. This value is perfect for passing to the poll call.
Definition at line 334 of file sched.c.
References ast_debug, ast_heap_peek(), ast_mutex_lock, ast_mutex_unlock, ast_tvdiff_ms(), ast_tvnow(), DEBUG, sched_context::lock, sched_context::sched_heap, and sched::when.
Referenced by background_detect_exec(), dial_exec_full(), do_cdr(), do_monitor(), do_refresh(), handle_speechrecognize(), misdn_tasks_thread_func(), network_thread(), sched_run(), speech_background(), wait_for_winner(), and waitstream_core().
long ast_sched_when | ( | struct sched_context * | con, |
int | id | ||
) |
Returns the number of seconds before an event takes place.
con | Context to use |
id | Id to dump |
Definition at line 664 of file sched.c.
References ast_debug, ast_hashtab_lookup(), ast_mutex_lock, ast_mutex_unlock, ast_tvnow(), DEBUG, sched::id, sched_context::lock, sched_context::schedq_ht, and sched::when.
Referenced by _sip_show_peer(), handle_cli_status(), and parse_register_contact().
struct sched_context* sched_context_create | ( | void | ) |
New schedule context.
Definition at line 246 of file sched.c.
References ast_calloc, ast_hashtab_create(), ast_hashtab_newsize_java(), ast_hashtab_resize_java(), ast_heap_create(), ast_mutex_init, sched_context::eventcnt, sched_context::lock, sched_cmp(), sched_context_destroy(), sched_hash(), sched_context::sched_heap, sched_time_cmp(), and sched_context::schedq_ht.
Referenced by __ast_channel_alloc_ap(), ast_cdr_engine_init(), ast_sched_thread_create(), dnsmgr_init(), load_module(), and misdn_tasks_init().
void sched_context_destroy | ( | struct sched_context * | c | ) |
destroys a schedule context Destroys (free's) the given sched_context structure
c | Context to free |
Definition at line 267 of file sched.c.
References ast_free, ast_hashtab_destroy(), ast_heap_destroy(), ast_heap_pop(), AST_LIST_REMOVE_HEAD, ast_mutex_destroy, ast_mutex_lock, ast_mutex_unlock, sched_context::lock, sched_context::sched_heap, sched_context::schedc, and sched_context::schedq_ht.
Referenced by ast_channel_destructor(), ast_hangup(), ast_sched_thread_destroy(), cdr_engine_shutdown(), dnsmgr_shutdown(), load_module(), misdn_tasks_destroy(), sched_context_create(), and unload_module().