Remove alloc and destroy callbacks from the taskprocessor.

Now user data is allocated by the creator of the taskprocessor
listener and that user data is passed into ast_taskprocessor_listener_alloc().
Similarly, freeing of the user data is left up to the user himself. He can
free the data when the taskprocessor shuts down, or he can choose to hold
onto it if it makes sense to do so.

This, unsurprisingly, makes threadpool allocation a LOT cleaner now.



git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379120 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Michelson
2013-01-15 18:40:36 +00:00
parent c80f86f007
commit 65c7d6e2c3
4 changed files with 82 additions and 133 deletions

View File

@@ -74,17 +74,6 @@ enum ast_tps_options {
struct ast_taskprocessor_listener;
struct ast_taskprocessor_listener_callbacks {
/*!
* \brief Allocate the listener's private data
*
* This is called during taskprocesor creation.
* It is not necessary to assign the private data to the listener.
*
* \param listener The listener to which the private data belongs
* \retval NULL Error while attempting to initialize private data
* \retval non-NULL Allocated private data
*/
void *(*alloc)(struct ast_taskprocessor_listener *listener);
/*!
* \brief The taskprocessor has started completely
*
@@ -111,7 +100,8 @@ struct ast_taskprocessor_listener_callbacks {
* \brief Indicates the taskprocessor wishes to die.
*
* All operations on the task processor must to be stopped in
* this callback.
* this callback. This is an opportune time to free the listener's
* user data if it is not going to be used anywhere else.
*
* After this callback returns, it is NOT safe to operate on the
* listener's reference to the taskprocessor.
@@ -119,15 +109,6 @@ struct ast_taskprocessor_listener_callbacks {
* \param listener The listener
*/
void (*shutdown)(struct ast_taskprocessor_listener *listener);
/*!
* \brief Destroy the listener's private data
*
* It is required that you free the private data in this callback
* in addition to the private data's individual fields.
*
* \param private_data The listener's private data
*/
void (*destroy)(void *private_data);
};
/*!
@@ -146,7 +127,7 @@ struct ast_taskprocessor_listener {
/*! The taskprocessor that the listener is listening to */
struct ast_taskprocessor *tps;
/*! Data private to the listener */
void *private_data;
void *user_data;
};
/*!
@@ -158,10 +139,11 @@ struct ast_taskprocessor_listener {
* callbacks.
*
* \param callbacks The callbacks to assign to the listener
* \param user_data The user data for the listener
* \retval NULL Failure
* \retval non-NULL The newly allocated taskprocessor listener
*/
struct ast_taskprocessor_listener *ast_taskprocessor_listener_alloc(const struct ast_taskprocessor_listener_callbacks *callbacks);
struct ast_taskprocessor_listener *ast_taskprocessor_listener_alloc(const struct ast_taskprocessor_listener_callbacks *callbacks, void *user_data);
/*!
* \brief Get a reference to a taskprocessor with the specified name and create the taskprocessor if necessary