diff options
author | David M. Lee <dlee@digium.com> | 2013-02-12 21:45:59 +0000 |
---|---|---|
committer | David M. Lee <dlee@digium.com> | 2013-02-12 21:45:59 +0000 |
commit | 222e8a3afb6aabb31052fe76fa4f57fe26f69688 (patch) | |
tree | d7f7494c130d9372bdc43592e762ee83b4a78aec /include | |
parent | e9ff351f06c1cb7ad0ee59b3ff09b804a23eb3a0 (diff) |
Add a serializer interface to the threadpool
This patch adds the ability to create a serializer from a thread pool. A
serializer is 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 thread from a
ast_threadpool. Think of it as a lightweight thread.
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 relys on
thread specific information, such as thread locals.
This patch also fixes a bug in how the 'was_empty' parameter is computed
for the push callback, and gets rid of the unused 'shutting_down' field.
Review: https://reviewboard.asterisk.org/r/2323/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@381326 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include')
-rw-r--r-- | include/asterisk/threadpool.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/include/asterisk/threadpool.h b/include/asterisk/threadpool.h index e18ba6c69..15093175a 100644 --- a/include/asterisk/threadpool.h +++ b/include/asterisk/threadpool.h @@ -177,4 +177,33 @@ int ast_threadpool_push(struct ast_threadpool *pool, int (*task)(void *data), vo * \param pool The pool to shut down */ void ast_threadpool_shutdown(struct ast_threadpool *pool); + +/*! + * \brief Serialized execution of tasks within a \ref ast_threadpool. + * + * \since 12.0.0 + * + * A \ref 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 thread from a \ref ast_threadpool. Think of it + * as a lightweight thread. + * + * While it guarantees that each task will complete before executing the next, + * there is no guarantee as to which thread from the \c pool individual tasks + * will execute. This normally only matters if your code relys on thread + * specific information, such as thread locals. + * + * Use ast_taskprocessor_unreference() to dispose of the returned \ref + * 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. + * + * \param name Name of the serializer. (must be unique) + * \param pool \ref ast_threadpool for execution. + * \return \ref ast_taskprocessor for enqueuing work. + * \return \c NULL on error. + */ +struct ast_taskprocessor *ast_threadpool_serializer(const char *name, struct ast_threadpool *pool); + #endif /* ASTERISK_THREADPOOL_H */ |