Asterisk - The Open Source Telephony Project
18.5.0
|
Scheduler Routines (from cheops-NG) More...
#include "asterisk.h"
#include <sys/time.h>
#include "asterisk/sched.h"
#include "asterisk/channel.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/heap.h"
#include "asterisk/threadstorage.h"
Go to the source code of this file.
Data Structures | |
struct | ast_sched_context |
struct | sched |
struct | sched_id |
Scheduler ID holder. More... | |
struct | sched_thread |
Macros | |
#define | DEBUG(a) |
#define | ID_QUEUE_INCREMENT 16 |
#define | SCHED_MAX_CACHE 128 |
Max num of schedule structs. More... | |
Functions | |
static void | __init_last_del_id (void) |
static int | add_ids (struct ast_sched_context *con) |
Add new scheduler IDs to the queue. More... | |
int | ast_sched_add (struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) |
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) |
Schedule callback(data) to happen when ms into the future. 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 *con) |
destroys a schedule context More... | |
int | ast_sched_del (struct ast_sched_context *con, int id) |
Delete the schedule entry with number "id". It's nearly impossible that there would be two or more in the list with that id. More... | |
void | ast_sched_dump (struct ast_sched_context *con) |
Dump the contents of the scheduler to LOG_DEBUG. 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) |
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) |
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) |
Launch all events which need to be run at this time. 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) |
Return the number of milliseconds until the next scheduled event. More... | |
long | ast_sched_when (struct ast_sched_context *con, int id) |
Returns the number of seconds before an event takes place. More... | |
static struct sched * | sched_alloc (struct ast_sched_context *con) |
static struct sched * | sched_find (struct ast_sched_context *con, int id) |
static void | sched_free (struct sched *task) |
static void | sched_release (struct ast_sched_context *con, struct sched *tmp) |
static void * | sched_run (void *data) |
static void | sched_settime (struct timeval *t, int when) |
given the last event *tv and the offset in milliseconds 'when', computes the next value, More... | |
static void | sched_thread_destroy (struct ast_sched_context *con) |
static int | sched_time_cmp (void *va, void *vb) |
static void | schedule (struct ast_sched_context *con, struct sched *s) |
Take a sched structure and put it in the queue, such that the soonest event is first in the list. More... | |
static int | set_sched_id (struct ast_sched_context *con, struct sched *new_sched) |
Variables | |
static struct ast_threadstorage | last_del_id = { .once = PTHREAD_ONCE_INIT , .key_init = __init_last_del_id , .custom_init = NULL , } |
Scheduler Routines (from cheops-NG)
Definition in file sched.c.
#define DEBUG | ( | a | ) |
Definition at line 36 of file sched.c.
Referenced by ast_sched_add_variable(), ast_sched_del(), ast_sched_runq(), ast_sched_wait(), and ast_sched_when().
#define SCHED_MAX_CACHE 128 |
Max num of schedule structs.
Definition at line 56 of file sched.c.
Referenced by sched_release().
|
static |
Add new scheduler IDs to the queue.
The | number of IDs added to the queue |
Definition at line 310 of file sched.c.
References ast_calloc, AST_LIST_INSERT_TAIL, sched_id::id, ast_sched_context::id_queue, ID_QUEUE_INCREMENT, ast_sched_context::id_queue_size, and sched_id::list.
Referenced by set_sched_id().
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 | ||
) |
Schedule callback(data) to happen when ms into the future.
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 | ||
) |
Delete the schedule entry with number "id". It's nearly impossible that there would be two or more in the list with that id.
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 | ) |
Dump the contents of the scheduler to LOG_DEBUG.
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 | ) |
Launch all events which need to be run at this time.
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 | ) |
Return the number of milliseconds until the next scheduled event.
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().
|
static |
Definition at line 378 of file sched.c.
References ast_calloc, ast_cond_init, AST_LIST_REMOVE_HEAD, sched::cond, sched_id::list, NULL, sched_release(), ast_sched_context::schedc, ast_sched_context::schedccnt, set_sched_id(), and tmp().
Referenced by ast_sched_add_variable().
|
static |
Definition at line 570 of file sched.c.
References ast_heap_peek(), ast_heap_size(), sched_id::id, NULL, ast_sched_context::sched_heap, and sched::sched_id.
Referenced by ast_sched_del(), ast_sched_find_data(), and ast_sched_when().
|
static |
Definition at line 258 of file sched.c.
References ast_cond_destroy, ast_free, sched::cond, and sched::sched_id.
Referenced by ast_sched_context_destroy(), and sched_release().
|
static |
Definition at line 358 of file sched.c.
References AST_LIST_INSERT_HEAD, AST_LIST_INSERT_TAIL, ast_sched_context::id_queue, sched_id::list, NULL, sched_free(), sched::sched_id, SCHED_MAX_CACHE, ast_sched_context::schedc, and ast_sched_context::schedccnt.
Referenced by ast_sched_clean_by_callback(), ast_sched_del(), ast_sched_runq(), and sched_alloc().
|
static |
Definition at line 132 of file sched.c.
References ast_cond_timedwait, ast_cond_wait, ast_mutex_lock, ast_mutex_unlock, ast_samp2tv(), ast_sched_runq(), ast_sched_wait(), ast_tvadd(), ast_tvnow(), sched_thread::cond, ast_sched_context::lock, NULL, ast_sched_context::sched_thread, and sched_thread::stop.
Referenced by ast_sched_start_thread().
|
static |
given the last event *tv and the offset in milliseconds 'when', computes the next value,
Definition at line 488 of file sched.c.
References ast_assert, ast_log, ast_samp2tv(), ast_tvadd(), ast_tvcmp(), ast_tvnow(), ast_tvzero(), and LOG_WARNING.
Referenced by ast_sched_add_variable(), and ast_sched_runq().
|
static |
Definition at line 173 of file sched.c.
References ast_cond_destroy, ast_cond_signal, ast_free, ast_mutex_lock, ast_mutex_unlock, AST_PTHREADT_NULL, sched_thread::cond, ast_sched_context::lock, NULL, ast_sched_context::sched_thread, sched_thread::stop, and sched_thread::thread.
Referenced by ast_sched_context_destroy(), and ast_sched_start_thread().
|
static |
Definition at line 223 of file sched.c.
References a, ast_tvcmp(), b, sched::tie_breaker, and sched::when.
Referenced by ast_sched_context_create().
|
static |
Take a sched structure and put it in the queue, such that the soonest event is first in the list.
Definition at line 458 of file sched.c.
References ast_heap_push, ast_heap_size(), ast_sched_context::highwater, ast_sched_context::sched_heap, sched::tie_breaker, and ast_sched_context::tie_breaker.
Referenced by ast_sched_add_variable(), and ast_sched_runq().
|
static |
Definition at line 348 of file sched.c.
References add_ids(), AST_LIST_EMPTY, AST_LIST_REMOVE_HEAD, ast_sched_context::id_queue, sched_id::list, and sched::sched_id.
Referenced by sched_alloc().
|
static |
Definition at line 58 of file sched.c.
Referenced by ast_sched_del().