Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
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... | |
int | ast_sched_del_nonrunning (struct ast_sched_context *con, int id) attribute_warn_unused_result |
Deletes a scheduled event with care against the event running. 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.
#define AST_SCHED_DEL_ACCESSOR | ( | sched, | |
obj, | |||
getter, | |||
setter | |||
) |
#define ast_sched_del_object | ( | obj, | |
destructor, | |||
con, | |||
id | |||
) |
schedule task to get deleted and call unref function
Only calls the unref function if the task is actually deleted by ast_sched_del_nonrunning. If a failure occurs or the task is currently running and not rescheduled then refcall is not invoked.
#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) |
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 |
-1 | on failure |
Definition at line 567 of file sched.c.
References ast_sched_add_variable(), sched::callback, sched::data, and sched::when.
Referenced by 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(), dns_query_recurring_resolution_callback(), do_register(), dundi_discover(), dundi_query(), dundi_send(), handle_cli_sched_bench(), handle_command_response(), iax2_hangup(), iax2_key_rotate(), iax2_sched_add(), mbl_call(), memory_cache_stale_update_full(), memory_cache_stale_update_object(), populate_addr(), precache_trans(), qualify_peer(), rtp_instance_parse_transport_wide_cc(), rtp_raw_write(), rtp_red_init(), run_task(), schedule_cache_expiration(), schedule_notification(), and transaction_sched_timer().
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
-1 | on failure |
Adds a scheduled event with rescheduling support.
Definition at line 526 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, ast_sched_context::eventcnt, ast_sched_context::lock, sched_alloc(), sched_settime(), ast_sched_context::sched_thread, schedule(), tmp(), sched::variable, and sched::when.
Referenced by 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 409 of file sched.c.
References ast_heap_peek(), ast_heap_remove(), ast_mutex_lock, ast_mutex_unlock, cleanup_cb(), current, ast_sched_context::lock, match(), 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.
NULL | on failure |
Definition at line 238 of file sched.c.
References ast_calloc, ast_heap_create, AST_LIST_HEAD_INIT_NOLOCK, ast_mutex_init, ast_sched_context_destroy(), NULL, sched_time_cmp(), and tmp().
Referenced by __ast_channel_alloc_ap(), aeap_general_initialize(), 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(), 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 271 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(), aeap_general_finalize(), 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(), 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 |
-1 | on failure |
0 | on success |
Deletes a scheduled event.
Definition at line 614 of file sched.c.
References ast_sched_del_nonrunning().
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(), and handle_cli_sched_bench().
int ast_sched_del_nonrunning | ( | struct ast_sched_context * | con, |
int | id | ||
) |
Deletes a scheduled event with care against the event running.
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 |
-1 | on failure |
-2 | event was running but was deleted because it was not rescheduled |
0 | on success |
Deletes a scheduled event with care against the event running.
Definition at line 627 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, id, sched_id::id, last_del_id, ast_sched_context::lock, LOG_ERROR, LOG_WARNING, NULL, sched::rescheduled, sched_find(), ast_sched_context::sched_heap, sched::sched_id, sched_release(), and ast_sched_context::sched_thread.
Referenced by ast_sched_del().
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 743 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_nonrunning(), and handle_dump_sched().
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 |
NULL | if not found |
Definition at line 589 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 | on failure |
Definition at line 559 of file sched.c.
References ast_sched_add(), AST_SCHED_DEL, sched::callback, sched::data, and sched::when.
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 | on failure |
Definition at line 514 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 705 of file sched.c.
References ast_heap_peek(), ast_heap_size(), ast_mutex_lock, ast_mutex_unlock, ast_str_append(), ast_str_set(), buf, 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.
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 |
Runs the queue.
Definition at line 786 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(), current, ast_sched_context::currently_executing, DEBUG, ast_sched_context::executing_thread_id, ast_sched_context::lock, NULL, ast_sched_context::sched_heap, sched_release(), sched_settime(), and schedule().
Referenced by AST_TEST_DEFINE(), background_detect_exec(), dial_exec_full(), do_cdr(), do_monitor(), do_monitor_headset(), do_refresh(), handle_speechrecognize(), network_thread(), sched_run(), speech_background(), 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 197 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 aeap_general_initialize(), ast_sip_initialize_distributor(), ast_sip_initialize_scheduler(), ast_sip_initialize_transport_management(), AST_TEST_DEFINE(), 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 |
-1 | if there is nothing there are no scheduled events (and thus the poll should not timeout) |
Determines number of seconds until the next outstanding event to take place.
Definition at line 433 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(), 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 851 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 handle_cli_status().