Asterisk - The Open Source Telephony Project
18.5.0
|
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) |
Remove a scheduler entry. More... | |
#define | AST_SCHED_DEL_ACCESSOR(sched, obj, getter, setter) |
#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) |
Typedefs | |
typedef int(* | ast_sched_cb) (const void *data) |
scheduler callback More... | |
Functions | |
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. More... | |
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. More... | |
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. More... | |
struct ast_sched_context * | ast_sched_context_create (void) |
Create a scheduler context. More... | |
void | ast_sched_context_destroy (struct ast_sched_context *c) |
destroys a schedule context More... | |
int | ast_sched_del (struct ast_sched_context *con, int id) attribute_warn_unused_result |
Deletes a scheduled event. More... | |
void | ast_sched_dump (struct ast_sched_context *con) |
Dumps the scheduler contents. More... | |
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. More... | |
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 More... | |
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 More... | |
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. More... | |
int | ast_sched_runq (struct ast_sched_context *con) |
Runs the queue. More... | |
int | ast_sched_start_thread (struct ast_sched_context *con) |
Start a thread for processing scheduler entries. More... | |
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. More... | |
long | ast_sched_when (struct ast_sched_context *con, int id) |
Returns the number of seconds before an event takes place. 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)) |
Remove a scheduler entry.
This is 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 46 of file sched.h.
Referenced by ack_trans(), apply_negotiated_sdp_stream(), ast_rtp_destroy(), ast_rtp_stop(), ast_sched_replace(), ast_sched_replace_variable(), build_gateway(), build_peer(), delete_users(), destroy_packet(), destroy_packets(), destroy_peer(), destroy_trans(), dnsmgr_start_refresh(), do_reload(), esc_entry_destructor(), handle_command_response(), handle_sip_publish_remove(), iax2_delete_from_sched(), iax2_destroy_helper(), iax2_frame_free(), iax2_poke_peer(), make_trunk(), mgcpsock_read(), misdn_tasks_remove(), qualify_peer(), realtime_peer(), reg_source_db(), sip_cc_agent_stop_offer_timer(), sip_cc_monitor_cancel_available_timer(), socket_process_helper(), start_batch_mode(), stream_stop(), unlink_peer(), and update_registry().
#define AST_SCHED_DEL_ACCESSOR | ( | sched, | |
obj, | |||
getter, | |||
setter | |||
) |
Definition at line 59 of file sched.h.
Referenced by filestream_close().
#define ast_sched_del_object | ( | obj, | |
destructor, | |||
con, | |||
id | |||
) |
schedule task to get deleted and call unref function
Only calls unref function if the delete succeeded.
Definition at line 80 of file sched.h.
Referenced by __cleanup_registration(), __shutdown_mwi_subscription(), __start_mwi_subscription(), __start_register_timeout(), __start_reregister_timeout(), __start_t38_abort_timer(), __stop_provisional_keepalive(), __stop_register_timeout(), __stop_reinvite_retry(), __stop_reinviteid(), __stop_retrans_pkt(), __stop_t38_abort_timer(), __update_provisional_keepalive_full(), ast_dns_resolve_recurring_cancel(), ast_rtp_stop(), build_peer(), do_cancel_destroy(), do_dialog_unlink_sched_items(), do_stop_session_timer(), handle_response_invite(), parse_register_contact(), peer_sched_cleanup(), pubsub_on_rx_publish_request(), remove_all_from_cache(), rtcp_debug_test_addr(), schedule_cache_expiration(), sip_poke_peer(), and sip_unregister().
#define AST_SCHED_REPLACE | ( | id, | |
sched, | |||
when, | |||
callback, | |||
data | |||
) | AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, 0) |
Definition at line 125 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 150 of file sched.h.
Referenced by build_peer(), handle_response_peerpoke(), handle_sip_publish_modify(), handle_sip_publish_refresh(), pubsub_on_rx_publish_request(), realtime_peer(), reg_source_db(), sip_call(), sip_keepalive_all_peers(), sip_poke_all_peers(), sip_poke_noanswer(), sip_poke_peer(), and sip_send_keepalive().
typedef int(* ast_sched_cb) (const void *data) |
int ast_sched_add | ( | struct ast_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 565 of file sched.c.
References ast_sched_add_variable().
Referenced by __sip_scheddestroy(), __start_mwi_subscription(), __start_register_timeout(), __start_reregister_timeout(), __start_session_timer(), __start_t38_abort_timer(), __update_provisional_keepalive_full(), ast_readaudio_callback(), ast_readvideo_callback(), ast_rtp_interpret(), ast_sched_replace(), ast_sip_schedule_task(), AST_TEST_DEFINE(), build_peer(), cc_generic_agent_start_offer_timer(), cc_generic_monitor_request_cc(), cleanup_registration(), create_esc_entry(), dialog_unlink_all(), dns_query_recurring_resolution_callback(), do_register(), dundi_discover(), dundi_query(), dundi_send(), handle_cli_sched_bench(), handle_command_response(), handle_keepalive_message(), handle_response_invite(), iax2_hangup(), iax2_key_rotate(), iax2_sched_add(), mbl_call(), memory_cache_stale_update_full(), memory_cache_stale_update_object(), mgcp_postrequest(), network_change_stasis_cb(), parse_register_contact(), populate_addr(), precache_trans(), qualify_peer(), rtcp_debug_test_addr(), rtp_instance_parse_transport_wide_cc(), rtp_raw_write(), rtp_red_init(), run_task(), sched_check_pendings(), schedule_cache_expiration(), schedule_notification(), shutdown_mwi_subscription(), sip_cancel_destroy(), sip_cc_agent_start_offer_timer(), sip_cc_monitor_request_cc(), sip_hangup(), sip_scheddestroy_full(), skinny_sched_add(), skinny_session(), start_mwi_subscription(), start_register_timeout(), start_reregister_timeout(), start_session_timer(), start_t38_abort_timer(), stop_provisional_keepalive(), stop_register_timeout(), stop_reinvite_retry(), stop_reinviteid(), stop_retrans_pkt(), stop_session_timer(), stop_t38_abort_timer(), and update_provisional_keepalive().
int ast_sched_add_variable | ( | struct ast_sched_context * | con, |
int | when, | ||
ast_sched_cb | callback, | ||
const void * | data, | ||
int | variable | ||
) |
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
Adds a scheduled event with rescheduling support.
Definition at line 524 of file sched.c.
References ast_cond_signal, ast_debug, ast_mutex_lock, ast_mutex_unlock, ast_sched_dump(), ast_tv(), sched::callback, sched_thread::cond, sched::data, DEBUG, sched::deleted, ast_sched_context::eventcnt, sched_id::id, ast_sched_context::lock, sched::resched, sched_alloc(), sched::sched_id, sched_settime(), ast_sched_context::sched_thread, schedule(), tmp(), sched::variable, and sched::when.
Referenced by __sip_reliable_xmit(), _misdn_tasks_add_variable(), apply_negotiated_sdp_stream(), ast_sched_add(), ast_sched_replace_variable(), dnsmgr_start_refresh(), do_reload(), global_loaded(), monitored_transport_state_callback(), start_batch_mode(), and stun_start_monitor().
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.
con | Scheduler Context |
match | Callback to match |
cleanup_cb | Callback to run |
Definition at line 407 of file sched.c.
References ast_heap_peek(), ast_heap_remove(), ast_mutex_lock, ast_mutex_unlock, sched::callback, cleanup_cb(), sched::data, ast_sched_context::lock, ast_sched_context::sched_heap, and sched_release().
Referenced by __unload_module(), ast_sip_destroy_transport_management(), and global_loaded().
struct ast_sched_context* ast_sched_context_create | ( | void | ) |
Create a scheduler context.
Definition at line 236 of file sched.c.
References ast_calloc, ast_heap_create, AST_LIST_HEAD_INIT_NOLOCK, ast_mutex_init, ast_sched_context_destroy(), ast_sched_context::eventcnt, ast_sched_context::id_queue, ast_sched_context::lock, NULL, ast_sched_context::sched_heap, sched_time_cmp(), and tmp().
Referenced by __ast_channel_alloc_ap(), ast_sip_initialize_distributor(), ast_sip_initialize_scheduler(), ast_sip_initialize_transport_management(), AST_TEST_DEFINE(), dns_core_init(), handle_cli_sched_bench(), load_module(), mbl_load_device(), misdn_tasks_init(), and stun_start_monitor().
void ast_sched_context_destroy | ( | struct ast_sched_context * | c | ) |
destroys a schedule context
c | Context to free |
Definition at line 269 of file sched.c.
References ast_free, ast_heap_destroy(), ast_heap_pop(), AST_LIST_REMOVE_HEAD, ast_mutex_destroy, ast_mutex_lock, ast_mutex_unlock, ast_sched_context::id_queue, sched_id::list, ast_sched_context::lock, NULL, sched_free(), ast_sched_context::sched_heap, ast_sched_context::sched_thread, sched_thread_destroy(), and ast_sched_context::schedc.
Referenced by __unload_module(), ast_channel_destructor(), ast_hangup(), ast_sched_context_create(), ast_sched_context_destroy_wrapper(), ast_sip_destroy_distributor(), ast_sip_destroy_scheduler(), ast_sip_destroy_transport_management(), ast_sip_initialize_scheduler(), ast_sip_initialize_transport_management(), AST_TEST_DEFINE(), cdr_engine_shutdown(), dns_shutdown(), handle_cli_sched_bench(), load_module(), mbl_load_device(), misdn_tasks_destroy(), stun_start_monitor(), stun_stop_monitor(), and unload_module().
int ast_sched_del | ( | struct ast_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.
Definition at line 610 of file sched.c.
References ast_cond_signal, ast_cond_wait, ast_debug, ast_heap_remove(), ast_log, ast_log_backtrace(), ast_mutex_lock, ast_mutex_unlock, ast_sched_dump(), ast_threadstorage_get(), sched::callback, sched::cond, sched_thread::cond, ast_sched_context::currently_executing, DEBUG, sched::deleted, ast_sched_context::executing_thread_id, sched_id::id, last_del_id, ast_sched_context::lock, LOG_ERROR, LOG_WARNING, NULL, sched_find(), ast_sched_context::sched_heap, sched::sched_id, sched_release(), and ast_sched_context::sched_thread.
Referenced by ast_rtp_prop_set(), ast_rtp_stop(), ast_sip_sched_task_cancel(), AST_TEST_DEFINE(), cc_generic_agent_stop_offer_timer(), cc_generic_monitor_cancel_available_timer(), destroy_event(), handle_cli_sched_bench(), handle_keepalive_message(), skinny_register(), skinny_sched_del(), and skinny_session_cleanup().
void ast_sched_dump | ( | struct ast_sched_context * | con | ) |
Dumps the scheduler contents.
Debugging: Dump the contents of the scheduler to stderr
con | Context to dump |
Dumps the scheduler contents.
Definition at line 712 of file sched.c.
References ast_heap_peek(), ast_heap_size(), ast_log, ast_mutex_lock, ast_mutex_unlock, ast_tvnow(), ast_tvsub(), DEBUG_ATLEAST, ast_sched_context::eventcnt, ast_sched_context::highwater, ast_sched_context::lock, LOG_DEBUG, ast_sched_context::sched_heap, and ast_sched_context::schedccnt.
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 ast_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 587 of file sched.c.
References ast_mutex_lock, ast_mutex_unlock, sched::data, ast_sched_context::lock, NULL, and sched_find().
int ast_sched_replace | ( | int | old_id, |
struct ast_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 557 of file sched.c.
References ast_sched_add(), and AST_SCHED_DEL.
Referenced by iax2_sched_replace().
int ast_sched_replace_variable | ( | int | old_id, |
struct ast_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 512 of file sched.c.
References ast_sched_add_variable(), and AST_SCHED_DEL.
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.
con | Schedule context to check |
buf | dynamic string to store report |
cbnames | to check against |
Definition at line 674 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, ast_sched_context::highwater, ast_cb_names::list, ast_sched_context::lock, ast_cb_names::numassocs, and ast_sched_context::sched_heap.
Referenced by sip_show_sched().
int ast_sched_runq | ( | struct ast_sched_context * | con | ) |
Runs the queue.
Run the queue, executing all callbacks which need to be performed at this time.
con | Scheduling context to run |
con | context to act upon |
Runs the queue.
Definition at line 755 of file sched.c.
References ast_cond_signal, ast_debug, ast_heap_peek(), ast_heap_pop(), ast_mutex_lock, ast_mutex_unlock, ast_tv(), ast_tvadd(), ast_tvcmp(), ast_tvnow(), sched::callback, sched::cond, ast_sched_context::currently_executing, sched::data, DEBUG, sched::deleted, ast_sched_context::executing_thread_id, ast_sched_context::lock, NULL, sched::resched, ast_sched_context::sched_heap, sched_release(), sched_settime(), schedule(), sched::variable, and sched::when.
Referenced by AST_TEST_DEFINE(), background_detect_exec(), dial_exec_full(), do_cdr(), do_monitor(), do_monitor_headset(), do_refresh(), handle_speechrecognize(), misdn_tasks_thread_func(), network_thread(), reload_config(), sched_run(), speech_background(), unload_module(), wait_for_winner(), and waitstream_core().
int ast_sched_start_thread | ( | struct ast_sched_context * | con | ) |
Start a thread for processing scheduler entries.
con | the scheduler context this thread will manage |
0 | success |
non-zero | failure |
Definition at line 195 of file sched.c.
References ast_calloc, ast_cond_init, ast_log, ast_pthread_create_background, AST_PTHREADT_NULL, sched_thread::cond, LOG_ERROR, NULL, sched_run(), ast_sched_context::sched_thread, sched_thread_destroy(), and sched_thread::thread.
Referenced by ast_sip_initialize_distributor(), ast_sip_initialize_scheduler(), ast_sip_initialize_transport_management(), dns_core_init(), load_module(), and stun_start_monitor().
int ast_sched_wait | ( | struct ast_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.
Definition at line 431 of file sched.c.
References ast_debug, ast_heap_peek(), ast_mutex_lock, ast_mutex_unlock, ast_tvdiff_ms(), ast_tvnow(), DEBUG, ast_sched_context::lock, ast_sched_context::sched_heap, and sched::when.
Referenced by AST_TEST_DEFINE(), background_detect_exec(), dial_exec_full(), do_cdr(), do_monitor(), do_monitor_headset(), 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 ast_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 814 of file sched.c.
References ast_debug, ast_mutex_lock, ast_mutex_unlock, ast_tvnow(), DEBUG, ast_sched_context::lock, sched_find(), and sched::when.
Referenced by _sip_show_peer(), handle_cli_status(), and parse_register_contact().