summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMatt Jordan <mjordan@digium.com>2015-06-26 13:35:07 -0500
committerGerrit Code Review <gerrit2@gerrit.digium.api>2015-06-26 13:35:07 -0500
commit0a1700d286ad130ab29ce70e8b291fa1f2f567a7 (patch)
tree06bdfbb79485b7505e143e538dd98b251959c079 /include
parentd8e61c04a4a933132330b9f127970cdac31af5cf (diff)
parent84c12f9e0c810c4816444dbd2bb8a6f4e5bfc1f9 (diff)
Merge "threadpool, res_pjsip: Add serializer group shutdown API calls." into 13
Diffstat (limited to 'include')
-rw-r--r--include/asterisk/res_pjsip.h17
-rw-r--r--include/asterisk/threadpool.h53
2 files changed, 70 insertions, 0 deletions
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index 24706c9a5..1f9276b41 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -1112,6 +1112,23 @@ struct ast_sip_endpoint *ast_sip_get_artificial_endpoint(void);
*/
struct ast_taskprocessor *ast_sip_create_serializer(void);
+struct ast_serializer_shutdown_group;
+
+/*!
+ * \brief Create a new serializer for SIP tasks
+ * \since 13.5.0
+ *
+ * See \ref ast_threadpool_serializer for more information on serializers.
+ * SIP creates serializers so that tasks operating on similar data will run
+ * in sequence.
+ *
+ * \param shutdown_group Group shutdown controller. (NULL if no group association)
+ *
+ * \retval NULL Failure
+ * \retval non-NULL Newly-created serializer
+ */
+struct ast_taskprocessor *ast_sip_create_serializer_group(struct ast_serializer_shutdown_group *shutdown_group);
+
/*!
* \brief Set a serializer on a SIP dialog so requests and responses are automatically serialized
*
diff --git a/include/asterisk/threadpool.h b/include/asterisk/threadpool.h
index e1e7727f5..942d14fc1 100644
--- a/include/asterisk/threadpool.h
+++ b/include/asterisk/threadpool.h
@@ -195,6 +195,28 @@ int ast_threadpool_push(struct ast_threadpool *pool, int (*task)(void *data), vo
*/
void ast_threadpool_shutdown(struct ast_threadpool *pool);
+struct ast_serializer_shutdown_group;
+
+/*!
+ * \brief Create a serializer group shutdown control object.
+ * \since 13.5.0
+ *
+ * \return ao2 object to control shutdown of a serializer group.
+ */
+struct ast_serializer_shutdown_group *ast_serializer_shutdown_group_alloc(void);
+
+/*!
+ * \brief Wait for the serializers in the group to shutdown with timeout.
+ * \since 13.5.0
+ *
+ * \param shutdown_group Group shutdown controller. (Returns 0 immediately if NULL)
+ * \param timeout Number of seconds to wait for the serializers in the group to shutdown.
+ * Zero if the timeout is disabled.
+ *
+ * \return Number of seriaizers that did not get shutdown within the timeout.
+ */
+int ast_serializer_shutdown_group_join(struct ast_serializer_shutdown_group *shutdown_group, int timeout);
+
/*!
* \brief Serialized execution of tasks within a \ref ast_threadpool.
*
@@ -218,9 +240,40 @@ void ast_threadpool_shutdown(struct ast_threadpool *pool);
*
* \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);
+/*!
+ * \brief Serialized execution of tasks within a \ref ast_threadpool.
+ * \since 13.5.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.
+ * \param shutdown_group Group shutdown controller. (NULL if no group association)
+ *
+ * \return \ref ast_taskprocessor for enqueuing work.
+ * \return \c NULL on error.
+ */
+struct ast_taskprocessor *ast_threadpool_serializer_group(const char *name,
+ struct ast_threadpool *pool, struct ast_serializer_shutdown_group *shutdown_group);
+
#endif /* ASTERISK_THREADPOOL_H */