Asterisk - The Open Source Telephony Project GIT-master-77d630f
|
Go to the source code of this file.
Data Structures | |
struct | ast_taskpool_options |
Macros | |
#define | AST_TASKPOOL_OPTIONS_VERSION 1 |
Enumerations | |
enum | ast_taskpool_selector { AST_TASKPOOL_SELECTOR_DEFAULT = 0 , AST_TASKPOOL_SELECTOR_LEAST_FULL , AST_TASKPOOL_SELECTOR_SEQUENTIAL } |
Selectors for choosing which taskprocessor in a pool to use. More... | |
Functions | |
struct ast_taskpool * | ast_taskpool_create (const char *name, const struct ast_taskpool_options *options) |
Create a new taskpool. More... | |
int | ast_taskpool_push (struct ast_taskpool *pool, int(*task)(void *data), void *data) attribute_warn_unused_result |
Push a task to the taskpool. More... | |
int | ast_taskpool_push_wait (struct ast_taskpool *pool, int(*task)(void *data), void *data) attribute_warn_unused_result |
Push a task to the taskpool, and wait for completion. More... | |
long | ast_taskpool_queue_size (struct ast_taskpool *pool) |
Get the current number of queued tasks in the taskpool. More... | |
struct ast_taskprocessor * | ast_taskpool_serializer (const char *name, struct ast_taskpool *pool) |
Serialized execution of tasks within a ast_taskpool. More... | |
struct ast_taskprocessor * | ast_taskpool_serializer_get_current (void) |
Get the taskpool serializer currently associated with this thread. More... | |
struct ast_taskprocessor * | ast_taskpool_serializer_group (const char *name, struct ast_taskpool *pool, struct ast_serializer_shutdown_group *shutdown_group) |
Serialized execution of tasks within a ast_taskpool. More... | |
int | ast_taskpool_serializer_push_wait (struct ast_taskprocessor *serializer, int(*task)(void *data), void *data) |
Push a task to a serializer, and wait for completion. More... | |
void | ast_taskpool_shutdown (struct ast_taskpool *pool) |
Shut down a taskpool and remove the underlying taskprocessors. More... | |
size_t | ast_taskpool_taskprocessors_count (struct ast_taskpool *pool) |
Get the current number of taskprocessors in the taskpool. More... | |
API providing queued task execution across threads.
Definition in file taskpool.h.
#define AST_TASKPOOL_OPTIONS_VERSION 1 |
Definition at line 69 of file taskpool.h.
Selectors for choosing which taskprocessor in a pool to use.
Enumerator | |
---|---|
AST_TASKPOOL_SELECTOR_DEFAULT | |
AST_TASKPOOL_SELECTOR_LEAST_FULL | |
AST_TASKPOOL_SELECTOR_SEQUENTIAL |
Definition at line 62 of file taskpool.h.
struct ast_taskpool * ast_taskpool_create | ( | const char * | name, |
const struct ast_taskpool_options * | options | ||
) |
Create a new taskpool.
This function creates a taskpool. Tasks may be pushed onto this task pool and will be automatically acted upon by taskprocessors within the pool.
Only a single taskpool with a given name may exist. This function will fail if a taskpool with the given name already exists.
name | The unique name for the taskpool |
options | The behavioral options for this taskpool |
NULL | Failed to create the taskpool |
non-NULL | The newly-created taskpool |
Definition at line 324 of file taskpool.c.
References ao2_alloc, ao2_bump, ao2_ref, ast_log, ast_sched_add(), AST_TASKPOOL_OPTIONS_VERSION, AST_TASKPOOL_SELECTOR_DEFAULT, AST_TASKPOOL_SELECTOR_LEAST_FULL, AST_TASKPOOL_SELECTOR_SEQUENTIAL, ast_taskpool_shutdown(), AST_VECTOR_APPEND, ast_taskpool::dynamic_taskprocessors, ast_taskpool_options::growth_threshold, ast_taskpool_options::initial_size, LOG_WARNING, ast_taskpool_options::max_size, ast_taskpool_options::minimum_size, ast_taskpool::name, name, NULL, ast_taskpool::options, options, ast_taskpool::selector, ast_taskpool::shrink_sched_id, ast_taskpool::static_taskprocessors, taskpool_dynamic_pool_shrink(), TASKPOOL_GROW_THRESHOLD, taskpool_least_full_selector(), taskpool_sequential_selector(), taskpool_taskprocessor_alloc(), taskpool_taskprocessors_init(), taskpool_taskprocessor::taskprocessor, and taskpool_taskprocessors::taskprocessors.
Referenced by AST_TEST_DEFINE(), handle_cli_taskpool_push_efficiency(), handle_cli_taskpool_push_serializer_efficiency(), and stasis_init().
int ast_taskpool_push | ( | struct ast_taskpool * | pool, |
int(*)(void *data) | task, | ||
void * | data | ||
) |
Push a task to the taskpool.
Tasks pushed into the taskpool will be automatically taken by one of the taskprocessors within
pool | The taskpool to add the task to |
task | The task to add |
data | The parameter for the task |
0 | success |
-1 | failure |
Definition at line 522 of file taskpool.c.
References ao2_bump, ao2_cleanup, ao2_lock, ao2_unlock, ast_taskprocessor_push(), ast_tvnow(), ast_taskpool_options::auto_increment, ast_taskpool::dynamic_taskprocessors, NULL, ast_taskpool::options, RAII_VAR, ast_taskpool::selector, ast_taskpool::shutting_down, ast_taskpool::static_taskprocessors, task(), taskpool_dynamic_pool_grow(), and taskpool_taskprocessor::taskprocessor.
Referenced by ast_taskpool_push_wait(), AST_TEST_DEFINE(), efficiency_task(), execute_tasks(), handle_cli_taskpool_push_efficiency(), and serializer_task_pushed().
int ast_taskpool_push_wait | ( | struct ast_taskpool * | pool, |
int(*)(void *data) | task, | ||
void * | data | ||
) |
Push a task to the taskpool, and wait for completion.
Tasks pushed into the taskpool will be automatically taken by one of the taskprocessors within
pool | The taskpool to add the task to |
task | The task to add |
data | The parameter for the task |
0 | success |
-1 | failure |
Definition at line 623 of file taskpool.c.
References ast_cond_wait, ast_mutex_lock, ast_mutex_unlock, ast_taskpool_get_current(), ast_taskpool_push(), sync_task(), task(), taskpool_sync_task_cleanup(), and taskpool_sync_task_init().
Referenced by AST_TEST_DEFINE().
long ast_taskpool_queue_size | ( | struct ast_taskpool * | pool | ) |
Get the current number of queued tasks in the taskpool.
pool | The taskpool to query |
The | number of queued tasks in the taskpool |
Definition at line 464 of file taskpool.c.
References ao2_lock, ao2_unlock, AST_VECTOR_CALLBACK_VOID, ast_taskpool::dynamic_taskprocessors, ast_taskpool::static_taskprocessors, TASKPOOL_QUEUE_SIZE_ADD, and taskpool_taskprocessors::taskprocessors.
struct ast_taskprocessor * ast_taskpool_serializer | ( | const char * | name, |
struct ast_taskpool * | pool | ||
) |
Serialized execution of tasks within a ast_taskpool.
A ast_taskprocessor with the same contract as a default taskprocessor (tasks execute serially) except instead of executing out of a dedicated thread, execution occurs in a taskprocessor from a ast_taskpool.
While it guarantees that each task will complete before executing the next, there is no guarantee as to which thread from the pool
individual tasks will execute. This normally only matters if your code relies on thread specific information, such as thread locals.
Use ast_taskprocessor_unreference() to dispose of the returned ast_taskprocessor.
Only a single taskprocessor with a given name may exist. This function will fail if a taskprocessor with the given name already exists.
name | Name of the serializer. (must be unique) |
pool | ast_taskpool for execution. |
NULL | on error. |
Definition at line 819 of file taskpool.c.
References ast_taskpool_serializer_group(), name, and NULL.
Referenced by AST_TEST_DEFINE(), handle_cli_taskpool_push_serializer_efficiency(), and internal_stasis_subscribe().
struct ast_taskprocessor * ast_taskpool_serializer_get_current | ( | void | ) |
Get the taskpool serializer currently associated with this thread.
serializer | on success. |
NULL | on error or no serializer associated with the thread. |
Definition at line 784 of file taskpool.c.
References ast_threadstorage_get_ptr().
Referenced by ast_taskpool_serializer_push_wait(), requeue_task(), serializer_efficiency_task(), and simple_task().
struct ast_taskprocessor * ast_taskpool_serializer_group | ( | const char * | name, |
struct ast_taskpool * | pool, | ||
struct ast_serializer_shutdown_group * | shutdown_group | ||
) |
Serialized execution of tasks within a ast_taskpool.
A ast_taskprocessor with the same contract as a default taskprocessor (tasks execute serially) except instead of executing out of a dedicated thread, execution occurs in a taskprocessor from a ast_taskpool.
While it guarantees that each task will complete before executing the next, there is no guarantee as to which thread from the pool
individual tasks will execute. This normally only matters if your code relies on thread specific information, such as thread locals.
Use ast_taskprocessor_unreference() to dispose of the returned ast_taskprocessor.
Only a single taskprocessor with a given name may exist. This function will fail if a taskprocessor with the given name already exists.
name | Name of the serializer. (must be unique) |
pool | ast_taskpool for execution. |
shutdown_group | Group shutdown controller. (NULL if no group association) |
NULL | on error. |
Definition at line 789 of file taskpool.c.
References ao2_ref, ast_serializer_shutdown_group_inc(), ast_taskprocessor_create_with_listener(), ast_taskprocessor_listener_alloc(), listener(), name, NULL, serializer_create(), serializer_tps_listener_callbacks, and shutdown_group.
Referenced by ast_serializer_taskpool_create(), and ast_taskpool_serializer().
int ast_taskpool_serializer_push_wait | ( | struct ast_taskprocessor * | serializer, |
int(*)(void *data) | task, | ||
void * | data | ||
) |
Push a task to a serializer, and wait for completion.
serializer | The serializer to add the task to |
task | The task to add |
data | The parameter for the task |
0 | success |
-1 | failure |
Definition at line 832 of file taskpool.c.
References ao2_lock, ao2_unlock, ast_cond_wait, ast_mutex_lock, ast_mutex_unlock, ast_taskpool_get_current(), ast_taskpool_serializer_get_current(), ast_taskprocessor_execute(), ast_taskprocessor_listener(), ast_taskprocessor_listener_get_user_data(), ast_taskprocessor_push(), ast_taskprocessor_size(), ast_threadstorage_set_ptr(), listener(), NULL, sync_task(), task(), taskpool_serializer_empty_task(), taskpool_sync_task_cleanup(), and taskpool_sync_task_init().
Referenced by AST_TEST_DEFINE(), and requeue_task().
void ast_taskpool_shutdown | ( | struct ast_taskpool * | pool | ) |
Shut down a taskpool and remove the underlying taskprocessors.
pool | The pool to shut down |
Definition at line 653 of file taskpool.c.
References ao2_lock, ao2_ref, ao2_unlock, AST_SCHED_DEL_UNREF, ast_taskpool::dynamic_taskprocessors, ast_taskpool::shrink_sched_id, ast_taskpool::shutting_down, ast_taskpool::static_taskprocessors, and taskpool_taskprocessors_cleanup().
Referenced by ast_taskpool_create(), AST_TEST_DEFINE(), handle_cli_taskpool_push_efficiency(), handle_cli_taskpool_push_serializer_efficiency(), and stasis_cleanup().
size_t ast_taskpool_taskprocessors_count | ( | struct ast_taskpool * | pool | ) |
Get the current number of taskprocessors in the taskpool.
pool | The taskpool to query |
The | number of taskprocessors in the taskpool |
Definition at line 451 of file taskpool.c.
References ao2_lock, ao2_unlock, AST_VECTOR_SIZE, ast_taskpool::dynamic_taskprocessors, ast_taskpool::static_taskprocessors, and taskpool_taskprocessors::taskprocessors.
Referenced by AST_TEST_DEFINE().