56#define SCHED_MAX_CACHE 128
124#ifdef SCHED_MAX_CACHE
140 struct timespec ts = {
158 ts.tv_sec = tv.tv_sec;
159 ts.tv_nsec = tv.tv_usec * 1000;
233 cmp =
b->tie_breaker -
a->tie_breaker;
252 offsetof(
struct sched, __heap_index)))) {
281#ifdef SCHED_MAX_CACHE
305#define ID_QUEUE_INCREMENT 16
328 for (i = original_size; i < new_size; ++i) {
371#ifdef SCHED_MAX_CACHE
388#ifdef SCHED_MAX_CACHE
500 "Bug likely: Negative time interval %d (interpreted as %u ms) requested!\n",
501 when, (
unsigned int) when);
545 res =
tmp->sched_id->id;
578 for (x = 1; x <= heap_size; x++) {
652 "BUG! Trying to delete sched %d from within the callback %p. "
653 "Ignoring so we don't deadlock\n",
692 else if (!s && *last_id !=
id) {
693 ast_debug(1,
"Attempted to delete nonexistent schedule entry %d!\n",
id);
712 memset(countlist, 0,
sizeof(countlist));
718 for (x = 1; x <= heap_size; x++) {
721 for (i = 0; i < cbnames->
numassocs; i++) {
726 if (i < cbnames->numassocs) {
735 for (i = 0; i < cbnames->
numassocs; i++) {
755#ifdef SCHED_MAX_CACHE
756 ast_log(
LOG_DEBUG,
"Asterisk Schedule Dump (%zu in Q, %u Total, %u Cache, %u high-water)\n",
759 ast_log(
LOG_DEBUG,
"Asterisk Schedule Dump (%zu in Q, %u Total, %u high-water)\n",
763 ast_log(
LOG_DEBUG,
"=============================================================\n");
765 ast_log(
LOG_DEBUG,
"+-----+-----------------+-----------------+-----------------+\n");
768 for (x = 1; x <= heap_size; x++) {
769 struct timeval delta;
777 (
long int)delta.tv_usec);
780 ast_log(
LOG_DEBUG,
"=============================================================\n");
832 current->rescheduled = res ? 1 : 0;
862 secs = s->
when.tv_sec - now.tv_sec;
Asterisk main include file. File version handling, generic pbx functions.
#define ast_calloc(num, len)
A wrapper for calloc()
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
General Asterisk PBX channel definitions.
struct ast_heap * ast_heap_destroy(struct ast_heap *h)
Destroy a max heap.
#define ast_heap_create(init_height, cmp_fn, index_offset)
Create a max heap.
void * ast_heap_pop(struct ast_heap *h)
Pop the max element off of the heap.
void * ast_heap_remove(struct ast_heap *h, void *elm)
Remove a specific element from a heap.
size_t ast_heap_size(struct ast_heap *h)
Get the current size of a heap.
#define ast_heap_push(h, elm)
Push an element on to a heap.
void * ast_heap_peek(struct ast_heap *h, unsigned int index)
Peek at an element on a heap.
#define DEBUG_ATLEAST(level)
#define ast_debug(level,...)
Log a DEBUG message.
void ast_log_backtrace(void)
Log a backtrace of the current thread's execution stack to the Asterisk log.
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Asterisk locking-related definitions:
#define ast_cond_destroy(cond)
#define ast_cond_wait(cond, mutex)
#define AST_PTHREADT_NULL
#define ast_cond_init(cond, attr)
#define ast_cond_timedwait(cond, mutex, time)
#define ast_mutex_init(pmutex)
#define ast_mutex_unlock(a)
pthread_cond_t ast_cond_t
#define ast_mutex_destroy(a)
#define ast_mutex_lock(a)
#define ast_cond_signal(cond)
static int cleanup_cb(void *obj, void *arg, int flags)
int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data)
Adds a scheduled event.
static int set_sched_id(struct ast_sched_context *con, struct sched *new_sched)
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
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.
static void * sched_run(void *data)
static struct ast_threadstorage last_del_id
static void sched_free(struct sched *task)
static void sched_thread_destroy(struct ast_sched_context *con)
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.
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.
#define SCHED_MAX_CACHE
Max num of schedule structs.
long ast_sched_when(struct ast_sched_context *con, int id)
Returns the number of seconds before an event takes place.
static struct sched * sched_alloc(struct ast_sched_context *con)
static void sched_settime(struct timeval *t, int when)
given the last event *tv and the offset in milliseconds 'when', computes the next value,
void ast_sched_dump(struct ast_sched_context *con)
Dump the contents of the scheduler to LOG_DEBUG.
static struct sched * sched_find(struct ast_sched_context *con, int id)
int ast_sched_start_thread(struct ast_sched_context *con)
Start a thread for processing scheduler entries.
static void sched_release(struct ast_sched_context *con, struct sched *tmp)
int ast_sched_runq(struct ast_sched_context *con)
Launch all events which need to be run at this time.
static int sched_time_cmp(void *va, void *vb)
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.
static int add_ids(struct ast_sched_context *con)
Add new scheduler IDs to the queue.
void ast_sched_context_destroy(struct ast_sched_context *con)
destroys a schedule context
#define ID_QUEUE_INCREMENT
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,...
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...
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
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
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.
int ast_sched_wait(struct ast_sched_context *con)
Return the number of milliseconds until the next scheduled event.
Scheduler Routines (derived from cheops)
#define AST_SCHED_DEL(sched, id)
Remove a scheduler entry.
int(* ast_sched_cb)(const void *data)
scheduler callback
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Structure for mutex and tracking information.
struct ast_sched_context::@388 id_queue
struct ast_sched_context::@387 schedc
struct sched_thread * sched_thread
pthread_t executing_thread_id
struct sched * currently_executing
struct ast_heap * sched_heap
Support for dynamic strings.
struct sched_id::@385 list
struct sched_id * sched_id
unsigned int tie_breaker
Tie breaker in case the when is the same for multiple entries.
static int task(void *data)
Queued task for baseline test.
Definitions to aid in the use of thread local storage.
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
struct timeval ast_samp2tv(unsigned int _nsamp, unsigned int _rate)
Returns a timeval corresponding to the duration of n samples at rate r. Useful to convert samples to ...
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
int ast_tvcmp(struct timeval _a, struct timeval _b)
Compress two struct timeval instances returning -1, 0, 1 if the first arg is smaller,...
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
struct timeval ast_tvsub(struct timeval a, struct timeval b)
Returns the difference of two timevals a - b.
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
#define ast_pthread_create_background(a, b, c, d)