33 #ifdef DEBUG_SCHEDULER 56 #define SCHED_MAX_CACHE 128 122 #ifdef SCHED_MAX_CACHE 138 struct timespec ts = {
156 ts.tv_sec = tv.tv_sec;
157 ts.tv_nsec = tv.tv_usec * 1000;
250 offsetof(
struct sched, __heap_index)))) {
279 #ifdef SCHED_MAX_CACHE 303 #define ID_QUEUE_INCREMENT 16 326 for (i = original_size; i < new_size; ++i) {
369 #ifdef SCHED_MAX_CACHE 386 #ifdef SCHED_MAX_CACHE 410 struct sched *current;
498 "Bug likely: Negative time interval %d (interpreted as %u ms) requested!\n",
499 when, (
unsigned int) when);
545 #ifdef DUMP_SCHEDULER 576 for (x = 1; x <= heap_size; x++) {
634 "BUG! Trying to delete sched %d from within the callback %p. " 635 "Ignoring so we don't deadlock\n",
652 #ifdef DUMP_SCHEDULER 661 if (!s && *last_id !=
id) {
662 ast_debug(1,
"Attempted to delete nonexistent schedule entry %d!\n",
id);
681 memset(countlist, 0,
sizeof(countlist));
687 for (x = 1; x <= heap_size; x++) {
690 for (i = 0; i < cbnames->
numassocs; i++) {
695 if (i < cbnames->numassocs) {
704 for (i = 0; i < cbnames->
numassocs; i++) {
724 #ifdef SCHED_MAX_CACHE 725 ast_log(
LOG_DEBUG,
"Asterisk Schedule Dump (%zu in Q, %u Total, %u Cache, %u high-water)\n",
728 ast_log(
LOG_DEBUG,
"Asterisk Schedule Dump (%zu in Q, %u Total, %u high-water)\n",
732 ast_log(
LOG_DEBUG,
"=============================================================\n");
734 ast_log(
LOG_DEBUG,
"+-----+-----------------+-----------------+-----------------+\n");
737 for (x = 1; x <= heap_size; x++) {
738 struct timeval delta;
746 (
long int)delta.tv_usec);
749 ast_log(
LOG_DEBUG,
"=============================================================\n");
757 struct sched *current;
796 if (res && !current->
deleted) {
825 secs = s->
when.tv_sec - now.tv_sec;
static struct ast_threadstorage last_del_id
static struct sched * sched_alloc(struct ast_sched_context *con)
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
static int sched_time_cmp(void *va, void *vb)
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
struct sched_id * sched_id
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
struct ast_heap * sched_heap
static void * sched_run(void *data)
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.
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
struct sched_thread * sched_thread
static void sched_settime(struct timeval *t, int when)
given the last event *tv and the offset in milliseconds 'when', computes the next value...
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.
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data)
Adds a scheduled event.
struct ast_heap * ast_heap_destroy(struct ast_heap *h)
Destroy a max heap.
void ast_sched_context_destroy(struct ast_sched_context *con)
destroys a schedule context
#define ast_cond_wait(cond, mutex)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
#define ast_cond_init(cond, attr)
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.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
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
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
#define ast_mutex_lock(a)
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
static void sched_thread_destroy(struct ast_sched_context *con)
Definitions to aid in the use of thread local storage.
void * ast_heap_pop(struct ast_heap *h)
Pop the max element off of the heap.
#define SCHED_MAX_CACHE
Max num of schedule structs.
#define ast_cond_signal(cond)
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.
struct sched_id::@414 list
static int task(void *data)
Queued task for baseline test.
pthread_cond_t ast_cond_t
static int cleanup_cb(void *obj, void *arg, int flags)
void ast_log_backtrace(void)
Log a backtrace of the current thread's execution stack to the Asterisk log.
#define ast_pthread_create_background(a, b, c, d)
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
pthread_t executing_thread_id
#define ast_debug(level,...)
Log a DEBUG message.
int ast_sched_start_thread(struct ast_sched_context *con)
Start a thread for processing scheduler entries.
#define ast_heap_push(h, elm)
General Asterisk PBX channel definitions.
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...
#define AST_SCHED_DEL(sched, id)
Remove a scheduler entry.
#define AST_PTHREADT_NULL
static struct sched * sched_find(struct ast_sched_context *con, int id)
Scheduler Routines (derived from cheops)
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 ...
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
int ast_sched_runq(struct ast_sched_context *con)
Launch all events which need to be run at this time.
AST_LIST_HEAD_NOLOCK(contactliststruct, contact)
struct ast_sched_context::@417 id_queue
#define ID_QUEUE_INCREMENT
int ast_sched_wait(struct ast_sched_context *con)
Return the number of milliseconds until the next scheduled event.
static void sched_release(struct ast_sched_context *con, struct sched *tmp)
int ast_tvcmp(struct timeval _a, struct timeval _b)
Compres two struct timeval instances returning -1, 0, 1 if the first arg is smaller, equal or greater to the second.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
long ast_sched_when(struct ast_sched_context *con, int id)
Returns the number of seconds before an event takes place.
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::@416 schedc
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
#define ast_cond_destroy(cond)
static void sched_free(struct sched *task)
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
#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_calloc(num, len)
A wrapper for calloc()
void ast_sched_dump(struct ast_sched_context *con)
Dump the contents of the scheduler to LOG_DEBUG.
int(* ast_sched_cb)(const void *data)
scheduler callback
struct sched * currently_executing
#define ast_heap_create(init_height, cmp_fn, index_offset)
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
void * ast_heap_remove(struct ast_heap *h, void *elm)
Remove a specific element from a heap.
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
size_t ast_heap_size(struct ast_heap *h)
Get the current size of a heap.
void * ast_heap_peek(struct ast_heap *h, unsigned int index)
Peek at an element on a heap.
struct timeval ast_tvsub(struct timeval a, struct timeval b)
Returns the difference of two timevals a - b.
#define ast_mutex_init(pmutex)
static int set_sched_id(struct ast_sched_context *con, struct sched *new_sched)
#define ast_mutex_destroy(a)
unsigned int tie_breaker
Tie breaker in case the when is the same for multiple entries.
#define DEBUG_ATLEAST(level)
#define ast_cond_timedwait(cond, mutex, time)
Structure for mutex and tracking information.
#define ast_mutex_unlock(a)