34 #ifdef DEBUG_SCHEDULER
35 #define DEBUG(a) do { \
76 #ifdef SCHED_MAX_CACHE
78 unsigned int schedccnt;
96 struct timespec ts = {
114 ts.tv_sec = tv.tv_sec;
115 ts.tv_nsec = tv.tv_usec * 1000;
150 pthread_join(st->
thread, NULL);
196 const void *data,
int variable)
229 const struct sched *as = a;
230 const struct sched *bs = b;
231 return as->
id != bs->
id;
236 const struct sched *s = obj;
237 unsigned int h = s->
id;
248 struct sched_context *tmp;
259 offsetof(
struct sched, __heap_index)))) {
273 #ifdef SCHED_MAX_CACHE
304 #ifdef SCHED_MAX_CACHE
321 #ifdef SCHED_MAX_CACHE
428 #ifdef DUMP_SCHEDULER
453 struct sched tmp,*res;
470 int _ast_sched_del(
struct sched_context *con,
int id,
const char *file,
int line,
const char *
function)
473 struct sched *s, tmp = {
500 #ifdef DUMP_SCHEDULER
507 if (!s && *last_id !=
id) {
508 ast_debug(1,
"Attempted to delete nonexistent schedule entry %d!\n",
id);
514 snprintf(buf,
sizeof(buf),
"s != NULL, id=%d",
id);
515 _ast_assert(0, buf, file, line,
function);
534 memset(countlist, 0,
sizeof(countlist));
540 for (x = 1; x <= heap_size; x++) {
543 for (i = 0; i < cbnames->
numassocs; i++) {
548 if (i < cbnames->numassocs) {
557 for (i = 0; i < cbnames->
numassocs; i++) {
571 #ifdef SCHED_MAX_CACHE
577 ast_debug(1,
"=============================================================\n");
578 ast_debug(1,
"|ID Callback Data Time (sec:ms) |\n");
579 ast_debug(1,
"+-----+-----------------+-----------------+-----------------+\n");
582 for (x = 1; x <= heap_size; x++) {
583 struct timeval delta;
586 ast_debug(1,
"|%.4d | %-15p | %-15p | %.6ld : %.6ld |\n",
591 (
long int)delta.tv_usec);
594 ast_debug(1,
"=============================================================\n");
602 struct sched *current;
625 ast_log(
LOG_ERROR,
"Sched entry %d was in the schedq list but not in the hashtab???\n", current->
id);
666 struct sched *s, tmp;
678 secs = s->
when.tv_sec - now.tv_sec;
static unsigned int sched_hash(const void *obj)
static struct ast_threadstorage last_del_id
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
int ast_sched_del(struct sched_context *con, int id) attribute_warn_unused_result
Deletes a scheduled event Remove this event from being run. A procedure should not remove its own eve...
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
void * ast_hashtab_lookup(struct ast_hashtab *tab, const void *obj)
Lookup this object in the hash table.
struct ast_sched_thread * ast_sched_thread_destroy(struct ast_sched_thread *st)
Destroy a scheduler and its thread.
int ast_hashtab_newsize_java(struct ast_hashtab *tab)
Create a prime number roughly 2x the current table size.
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
struct ast_sched_thread * ast_sched_thread_create(void)
Create a scheduler with a dedicated thread.
int ast_sched_thread_add_variable(struct ast_sched_thread *st, int when, ast_sched_cb cb, const void *data, int variable)
Add a variable reschedule time scheduler entry.
static void sched_release(struct sched_context *con, struct sched *tmp)
int ast_sched_add_variable(struct sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result
Schedule callback(data) to happen when ms into the future.
struct ast_hashtab * schedq_ht
static struct sched * sched_alloc(struct sched_context *con)
static void * sched_run(void *data)
int ast_sched_add(struct sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
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.
void ast_sched_dump(struct sched_context *con)
Dumps the scheduler contents Debugging: Dump the contents of the scheduler to stderr.
struct sched_context::@297 schedc
Generic (perhaps overly so) hashtable implementation Hash Table support in Asterisk.
int ast_heap_push(struct ast_heap *h, void *elm)
Push an element on to a heap.
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
struct ast_heap * ast_heap_destroy(struct ast_heap *h)
Destroy a max heap.
#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)
#define SCHED_MAX_CACHE
Max num of schedule structs.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
#define ast_mutex_lock(a)
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
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 ast_cond_signal(cond)
int ast_hashtab_resize_java(struct ast_hashtab *tab)
Determines if a table resize should occur using the Java algorithm (if the table load factor is 75% o...
pthread_cond_t ast_cond_t
#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.
#define ast_debug(level,...)
Log a DEBUG message.
A set of macros to manage doubly-linked lists.
General Asterisk PBX channel definitions.
#define AST_SCHED_DEL(sched, id)
a loop construct to ensure that the scheduled task get deleted. The idea is that if we loop attemptin...
struct ast_heap * sched_heap
static int sched_cmp(const void *a, const void *b)
#define AST_PTHREADT_NULL
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 ...
void ast_sched_report(struct sched_context *con, struct ast_str **buf, struct ast_cb_names *cbnames)
Show statics on what it is in the schedule queue.
int ast_sched_replace(int old_id, struct sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
replace a scheduler entry
A set of macros to manage forward-linked lists.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
struct ast_hashtab * ast_hashtab_create(int initial_buckets, int(*compare)(const void *a, const void *b), int(*resize)(struct ast_hashtab *), int(*newsize)(struct ast_hashtab *tab), unsigned int(*hash)(const void *obj), int do_locking)
Create the hashtable list.
struct sched_context * context
const void * ast_sched_find_data(struct sched_context *con, int id)
Find a sched structure and return the data field associated with it.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
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.
void sched_context_destroy(struct sched_context *c)
destroys a schedule context Destroys (free's) the given sched_context structure
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
long ast_sched_when(struct sched_context *con, int id)
Returns the number of seconds before an event takes place.
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
#define ast_cond_destroy(cond)
static void schedule(struct 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_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.
int ast_sched_replace_variable(int old_id, struct sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result
replace a scheduler entry
struct sched_context * ast_sched_thread_get_context(struct ast_sched_thread *st)
Get the scheduler context for a given ast_sched_thread.
void ast_sched_thread_poke(struct ast_sched_thread *st)
Force re-processing of the scheduler context.
static int sched_time_cmp(void *a, void *b)
int ast_sched_runq(struct sched_context *con)
Runs the queue.
void * ast_heap_remove(struct ast_heap *h, void *elm)
Remove a specific element from a heap.
struct sched_context * sched_context_create(void)
New schedule context.
int ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj)
Check and insert new object only if it is not there.
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.
struct ast_heap * ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn, ssize_t index_offset)
Create a max heap.
int ast_sched_wait(struct sched_context *con) attribute_warn_unused_result
Determines number of seconds until the next outstanding event to take place Determine the number of s...
void * ast_heap_peek(struct ast_heap *h, unsigned int index)
Peek at an element on a heap.
int(* ast_sched_cb)(const void *data)
callback for a cheops scheduler A cheops scheduler callback takes a pointer with callback data and ...
static int sched_settime(struct timeval *t, int when)
given the last event *tv and the offset in milliseconds 'when', computes the next value...
struct timeval ast_tvsub(struct timeval a, struct timeval b)
Returns the difference of two timevals a - b.
int ast_sched_thread_add(struct ast_sched_thread *st, int when, ast_sched_cb cb, const void *data)
Add a scheduler entry.
#define ast_mutex_init(pmutex)
#define ast_mutex_destroy(a)
#define ast_cond_timedwait(cond, mutex, time)
Structure for mutex and tracking information.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
#define ast_mutex_unlock(a)
void ast_hashtab_destroy(struct ast_hashtab *tab, void(*objdestroyfunc)(void *obj))
This func will free the hash table and all its memory.
void * ast_hashtab_remove_this_object(struct ast_hashtab *tab, void *obj)
Hash the object and then compare ptrs in bucket list instead of calling the compare routine...