Asterisk - The Open Source Telephony Project
21.4.1
|
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. Deprecated in favor of ast_sched_del_nonrunning which checks running event status. More... | |
int | ast_sched_del_nonrunning (struct ast_sched_context *con, int id) |
Delete the schedule entry with number "id". If running, wait for the task to complete, check to see if it is rescheduled then schedule the release. 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, | |
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. | |
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 SCHED_MAX_CACHE 128 |
|
static |
Add new scheduler IDs to the queue.
The | number of IDs added to the queue |
Definition at line 312 of file sched.c.
References ast_calloc, AST_LIST_INSERT_TAIL, sched_id::id, ast_sched_context::id_queue, and ast_sched_context::id_queue_size.
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().
Referenced by ast_sched_replace(), ast_sip_schedule_task(), dns_query_recurring_resolution_callback(), do_register(), rtp_raw_write(), and rtp_red_init().
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 526 of file sched.c.
References ast_debug, ast_sched_dump(), ast_tv(), sched::callback, sched::data, sched::deleted, ast_sched_context::eventcnt, sched_id::id, sched::resched, sched::sched_id, sched_settime(), schedule(), sched::variable, and sched::when.
Referenced by ast_sched_add(), ast_sched_replace_variable(), dnsmgr_start_refresh(), and start_batch_mode().
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(), sched::callback, and sched::data.
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_sched_context_destroy(), ast_sched_context::eventcnt, and ast_sched_context::id_queue.
Referenced by __ast_channel_alloc_ap(), ast_sip_initialize_scheduler(), dns_core_init(), load_module(), and mbl_load_device().
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_heap_destroy(), ast_heap_pop(), AST_LIST_REMOVE_HEAD, ast_sched_context::id_queue, and ast_sched_context::schedc.
Referenced by ast_channel_destructor(), ast_hangup(), ast_sched_context_create(), ast_sip_initialize_scheduler(), load_module(), mbl_load_device(), 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. Deprecated in favor of ast_sched_del_nonrunning which checks running event status.
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(), and ast_sip_sched_task_cancel().
int ast_sched_del_nonrunning | ( | struct ast_sched_context * | con, |
int | id | ||
) |
Delete the schedule entry with number "id". If running, wait for the task to complete, check to see if it is rescheduled then schedule the release. It's nearly impossible that there would be two or more in the list with that id.
Deletes a scheduled event with care against the event running.
Definition at line 627 of file sched.c.
References ast_debug, ast_heap_remove(), ast_log_backtrace(), ast_sched_dump(), ast_threadstorage_get(), sched::callback, sched::cond, ast_sched_context::currently_executing, sched::deleted, ast_sched_context::executing_thread_id, sched_id::id, sched::rescheduled, and sched::sched_id.
Referenced by ast_sched_del().
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 743 of file sched.c.
References ast_heap_peek(), ast_heap_size(), ast_tvnow(), ast_tvsub(), ast_sched_context::eventcnt, and ast_sched_context::highwater.
Referenced by ast_sched_add_variable(), and ast_sched_del_nonrunning().
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 sched::data.
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(), and AST_SCHED_DEL.
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_str_append(), ast_str_set(), sched::callback, and ast_sched_context::highwater.
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 786 of file sched.c.
References ast_debug, ast_heap_peek(), ast_heap_pop(), ast_tv(), ast_tvadd(), ast_tvcmp(), ast_tvnow(), sched::callback, sched::cond, ast_sched_context::currently_executing, sched::data, sched::deleted, ast_sched_context::executing_thread_id, sched::resched, sched::rescheduled, sched_settime(), schedule(), sched::variable, and sched::when.
Referenced by dial_exec_full(), speech_background(), 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.
Referenced by ast_sip_initialize_scheduler(), dns_core_init(), and load_module().
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 433 of file sched.c.
References ast_debug, ast_heap_peek(), ast_tvdiff_ms(), ast_tvnow(), and sched::when.
Referenced by dial_exec_full(), speech_background(), 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_tvnow(), and sched::when.