Maintain a container of uniquely-named taskprocessor threads that can be shared across modules. More...
#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/module.h"
#include "asterisk/time.h"
#include "asterisk/astobj2.h"
#include "asterisk/cli.h"
#include "asterisk/taskprocessor.h"
Go to the source code of this file.
Data Structures | |
struct | ast_taskprocessor |
A ast_taskprocessor structure is a singleton by name. More... | |
struct | ast_taskprocessor::tps_queue |
Taskprocessor queue. More... | |
struct | tps_task |
tps_task structure is queued to a taskprocessor More... | |
struct | tps_taskprocessor_stats |
tps_taskprocessor_stats maintain statistics for a taskprocessor. More... | |
Macros | |
#define | TPS_MAX_BUCKETS 7 |
Functions | |
struct ast_taskprocessor * | ast_taskprocessor_get (const char *name, enum ast_tps_options create) |
Get a reference to a taskprocessor with the specified name and create the taskprocessor if necessary. More... | |
const char * | ast_taskprocessor_name (struct ast_taskprocessor *tps) |
Return the name of the taskprocessor singleton. More... | |
int | ast_taskprocessor_push (struct ast_taskprocessor *tps, int(*task_exe)(void *datap), void *datap) |
Push a task into the specified taskprocessor queue and signal the taskprocessor thread. More... | |
void * | ast_taskprocessor_unreference (struct ast_taskprocessor *tps) |
Unreference the specified taskprocessor and its reference count will decrement. More... | |
int | ast_tps_init (void) |
static char * | cli_tps_ping (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | cli_tps_report (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static int | tps_cmp_cb (void *obj, void *arg, int flags) |
The astobj2 compare callback for taskprocessors. More... | |
static int | tps_hash_cb (const void *obj, const int flags) |
The astobj2 hash callback for taskprocessors. More... | |
static int | tps_ping_handler (void *datap) |
CLI taskprocessor ping <blah>handler function. More... | |
static void * | tps_processing_function (void *data) |
The task processing function executed by a taskprocessor. More... | |
static void | tps_shutdown (void) |
static struct tps_task * | tps_task_alloc (int(*task_exe)(void *datap), void *datap) |
static void * | tps_task_free (struct tps_task *task) |
static int | tps_taskprocessor_depth (struct ast_taskprocessor *tps) |
Return the size of the taskprocessor queue. More... | |
static void | tps_taskprocessor_destroy (void *tps) |
Destroy the taskprocessor when its refcount reaches zero. More... | |
static struct tps_task * | tps_taskprocessor_pop (struct ast_taskprocessor *tps) |
Remove the front task off the taskprocessor queue. More... | |
static char * | tps_taskprocessor_tab_complete (struct ast_taskprocessor *p, struct ast_cli_args *a) |
Variables | |
static ast_cond_t | cli_ping_cond |
CLI taskprocessor ping <blah>operation requires a ping condition. More... | |
static ast_mutex_t | cli_ping_cond_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } |
CLI taskprocessor ping <blah>operation requires a ping condition lock. More... | |
static struct ast_cli_entry | taskprocessor_clis [] |
static struct ao2_container * | tps_singletons |
tps_singletons is the astobj2 container for taskprocessor singletons More... | |
Maintain a container of uniquely-named taskprocessor threads that can be shared across modules.
Definition in file taskprocessor.c.
#define TPS_MAX_BUCKETS 7 |
Definition at line 87 of file taskprocessor.c.
Referenced by ast_tps_init().
struct ast_taskprocessor* ast_taskprocessor_get | ( | const char * | name, |
enum ast_tps_options | create | ||
) |
Get a reference to a taskprocessor with the specified name and create the taskprocessor if necessary.
The default behavior of instantiating a taskprocessor if one does not already exist can be disabled by specifying the TPS_REF_IF_EXISTS ast_tps_options as the second argument to ast_taskprocessor_get().
name | The name of the taskprocessor |
create | Use 0 by default or specify TPS_REF_IF_EXISTS to return NULL if the taskprocessor does not already exist return A pointer to a reference counted taskprocessor under normal conditions, or NULL if the TPS_REF_IF_EXISTS reference type is specified and the taskprocessor does not exist |
Definition at line 424 of file taskprocessor.c.
References ao2_alloc, ao2_find, ao2_link, ao2_lock, ao2_ref, ao2_unlock, ast_calloc, ast_cond_init, ast_log(), ast_mutex_init, ast_pthread_create, AST_PTHREADT_NULL, ast_strdup, ast_strlen_zero(), LOG_ERROR, LOG_WARNING, name, ast_taskprocessor::name, OBJ_POINTER, ast_taskprocessor::poll_cond, ast_taskprocessor::poll_thread, ast_taskprocessor::poll_thread_run, ast_taskprocessor::stats, ast_taskprocessor::taskprocessor_lock, tps_processing_function(), TPS_REF_IF_EXISTS, tps_singletons, and tps_taskprocessor_destroy().
Referenced by ast_cc_init(), ast_event_init(), cli_tps_ping(), load_module(), load_objects(), and load_pbx().
const char* ast_taskprocessor_name | ( | struct ast_taskprocessor * | tps | ) |
Return the name of the taskprocessor singleton.
Definition at line 412 of file taskprocessor.c.
References ast_log(), LOG_ERROR, and ast_taskprocessor::name.
int ast_taskprocessor_push | ( | struct ast_taskprocessor * | tps, |
int(*)(void *datap) | task_exe, | ||
void * | datap | ||
) |
Push a task into the specified taskprocessor queue and signal the taskprocessor thread.
tps | The taskprocessor structure |
task_exe | The task handling function to push into the taskprocessor queue |
datap | The data to be used by the task handling function |
0 | success |
-1 | failure |
Definition at line 499 of file taskprocessor.c.
References ast_cond_signal, AST_LIST_INSERT_TAIL, ast_log(), ast_mutex_lock, ast_mutex_unlock, LOG_ERROR, ast_taskprocessor::name, ast_taskprocessor::poll_cond, ast_taskprocessor::taskprocessor_lock, ast_taskprocessor::tps_queue, ast_taskprocessor::tps_queue_size, and tps_task_alloc().
Referenced by ast_cc_agent_status_response(), ast_cc_monitor_failed(), ast_cc_monitor_party_b_free(), ast_cc_monitor_status_request(), ast_cc_monitor_stop_ringing(), ast_event_queue(), cc_request_state_change(), cli_tps_ping(), device_state_cb(), generic_agent_devstate_cb(), generic_monitor_devstate_cb(), handle_cc_status(), iax2_transmit(), mwi_sub_event_cb(), and mwi_unsub_event_cb().
void* ast_taskprocessor_unreference | ( | struct ast_taskprocessor * | tps | ) |
Unreference the specified taskprocessor and its reference count will decrement.
Taskprocessors use astobj2 and will unlink from the taskprocessor singleton container and destroy themself when the taskprocessor reference count reaches zero.
tps | taskprocessor to unreference |
Definition at line 485 of file taskprocessor.c.
References ao2_link, ao2_lock, ao2_ref, ao2_unlink, ao2_unlock, and tps_singletons.
Referenced by __unload_module(), cc_shutdown(), event_shutdown(), unload_module(), and unload_pbx().
int ast_tps_init | ( | void | ) |
Provided by taskprocessor.c
Definition at line 134 of file taskprocessor.c.
References ao2_container_alloc, ARRAY_LEN, ast_cli_register_multiple(), ast_cond_init, ast_log(), ast_register_atexit(), cli_ping_cond, LOG_ERROR, taskprocessor_clis, tps_cmp_cb(), tps_hash_cb(), TPS_MAX_BUCKETS, tps_shutdown(), and tps_singletons.
Referenced by main().
|
static |
Definition at line 205 of file taskprocessor.c.
References ao2_ref, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_cond_timedwait, ast_mutex_lock, ast_mutex_unlock, ast_samp2tv(), ast_taskprocessor_get(), ast_taskprocessor_push(), ast_tvadd(), ast_tvnow(), ast_tvsub(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, cli_ping_cond, cli_ping_cond_lock, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, name, tps_ping_handler(), TPS_REF_IF_EXISTS, tps_taskprocessor_tab_complete(), and ast_cli_entry::usage.
|
static |
Definition at line 251 of file taskprocessor.c.
References tps_taskprocessor_stats::_tasks_processed_count, ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_cli_args::argc, ast_cli_entry::args, ast_cli(), ast_copy_string(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, tps_taskprocessor_stats::max_qsize, name, ast_taskprocessor::name, ast_taskprocessor::stats, ast_taskprocessor::tps_queue_size, tps_singletons, and ast_cli_entry::usage.
|
static |
The astobj2 compare callback for taskprocessors.
Definition at line 355 of file taskprocessor.c.
References CMP_MATCH, CMP_STOP, and ast_taskprocessor::name.
Referenced by ast_tps_init().
|
static |
The astobj2 hash callback for taskprocessors.
Definition at line 347 of file taskprocessor.c.
References ast_str_case_hash(), and ast_taskprocessor::name.
Referenced by ast_tps_init().
|
static |
CLI taskprocessor ping <blah>handler function.
Definition at line 196 of file taskprocessor.c.
References ast_cond_signal, ast_mutex_lock, ast_mutex_unlock, cli_ping_cond, and cli_ping_cond_lock.
Referenced by cli_tps_ping().
|
static |
The task processing function executed by a taskprocessor.
Definition at line 292 of file taskprocessor.c.
References tps_taskprocessor_stats::_tasks_processed_count, ast_cond_wait, ast_log(), ast_mutex_lock, ast_mutex_unlock, tps_task::datap, tps_task::execute, LOG_ERROR, LOG_WARNING, tps_taskprocessor_stats::max_qsize, ast_taskprocessor::poll_cond, ast_taskprocessor::poll_thread_run, ast_taskprocessor::stats, ast_taskprocessor::taskprocessor_lock, tps_task_free(), tps_taskprocessor_depth(), and tps_taskprocessor_pop().
Referenced by ast_taskprocessor_get().
|
static |
Definition at line 126 of file taskprocessor.c.
References ao2_t_ref, ARRAY_LEN, ast_cli_unregister_multiple(), taskprocessor_clis, and tps_singletons.
Referenced by ast_tps_init().
|
static |
Definition at line 151 of file taskprocessor.c.
References ast_calloc, tps_task::datap, and tps_task::execute.
Referenced by ast_taskprocessor_push().
|
static |
Definition at line 162 of file taskprocessor.c.
References ast_free.
Referenced by tps_processing_function().
|
static |
Return the size of the taskprocessor queue.
Definition at line 406 of file taskprocessor.c.
References ast_taskprocessor::tps_queue_size.
Referenced by tps_processing_function().
|
static |
Destroy the taskprocessor when its refcount reaches zero.
Definition at line 363 of file taskprocessor.c.
References ast_cond_destroy, ast_cond_signal, ast_free, ast_log(), ast_mutex_destroy, ast_mutex_lock, ast_mutex_unlock, AST_PTHREADT_NULL, LOG_DEBUG, LOG_ERROR, ast_taskprocessor::name, ast_taskprocessor::poll_cond, ast_taskprocessor::poll_thread, ast_taskprocessor::poll_thread_run, ast_taskprocessor::stats, and ast_taskprocessor::taskprocessor_lock.
Referenced by ast_taskprocessor_get().
|
static |
Remove the front task off the taskprocessor queue.
Definition at line 390 of file taskprocessor.c.
References AST_LIST_REMOVE_HEAD, ast_log(), ast_mutex_lock, ast_mutex_unlock, LOG_ERROR, ast_taskprocessor::taskprocessor_lock, ast_taskprocessor::tps_queue, and ast_taskprocessor::tps_queue_size.
Referenced by tps_processing_function().
|
static |
Definition at line 171 of file taskprocessor.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_strdup, ast_cli_args::n, name, ast_taskprocessor::name, ast_cli_args::pos, tps_singletons, and ast_cli_args::word.
Referenced by cli_tps_ping().
|
static |
CLI taskprocessor ping <blah>operation requires a ping condition.
Definition at line 92 of file taskprocessor.c.
Referenced by ast_tps_init(), cli_tps_ping(), and tps_ping_handler().
|
static |
CLI taskprocessor ping <blah>operation requires a ping condition lock.
Definition at line 95 of file taskprocessor.c.
Referenced by cli_tps_ping(), and tps_ping_handler().
|
static |
Definition at line 120 of file taskprocessor.c.
Referenced by ast_tps_init(), and tps_shutdown().
|
static |
tps_singletons is the astobj2 container for taskprocessor singletons
Definition at line 89 of file taskprocessor.c.
Referenced by ast_taskprocessor_get(), ast_taskprocessor_unreference(), ast_tps_init(), cli_tps_report(), tps_shutdown(), and tps_taskprocessor_tab_complete().