mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-15 00:41:02 +00:00
Move taskprocessors to use a listener model.
Taskprocessors are now divided into two units: the task queue and their listeners. When a task is added to the queue, the listener is notified and can take whatever action is desired. This means that taskprocessors are no longer confined to having their tasks executed within a single thread. A default taskprocessor listener has been added that mirrors the old taskprocessor behavior. I've tested it by running Asterisk and placing calls. It appears to work as expected. I'm going to do some cleaning up first and then write some unit tests to be sure everything works as expected. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376118 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -60,6 +60,21 @@ enum ast_tps_options {
|
||||
TPS_REF_IF_EXISTS = (1 << 0),
|
||||
};
|
||||
|
||||
struct ast_taskprocessor_listener;
|
||||
|
||||
struct ast_taskprocessor_listener_callbacks {
|
||||
/*! Indicates a task was pushed to the processor */
|
||||
void (*task_pushed)(struct ast_taskprocessor_listener *listener, int was_empty);
|
||||
/*! Indicates the task processor has become empty */
|
||||
void (*emptied)(struct ast_taskprocessor_listener *listener);
|
||||
};
|
||||
|
||||
struct ast_taskprocessor_listener {
|
||||
struct ast_taskprocessor_listener_callbacks *callbacks;
|
||||
struct ast_taskprocessor *tps;
|
||||
void *private_data;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Get a reference to a taskprocessor with the specified name and create the taskprocessor if necessary
|
||||
*
|
||||
@@ -74,6 +89,16 @@ enum ast_tps_options {
|
||||
*/
|
||||
struct ast_taskprocessor *ast_taskprocessor_get(const char *name, enum ast_tps_options create);
|
||||
|
||||
/*!
|
||||
* \brief Create a taskprocessor with a custom listener
|
||||
*
|
||||
* \param name The name of the taskprocessor to create
|
||||
* \param listener The listener for operations on this taskprocessor
|
||||
* \retval NULL Failure
|
||||
* \reval non-NULL success
|
||||
*/
|
||||
struct ast_taskprocessor *ast_taskprocessor_create_with_listener(const char *name, struct ast_taskprocessor_listener *listener);
|
||||
|
||||
/*!
|
||||
* \brief Unreference the specified taskprocessor and its reference count will decrement.
|
||||
*
|
||||
@@ -96,6 +121,14 @@ void *ast_taskprocessor_unreference(struct ast_taskprocessor *tps);
|
||||
*/
|
||||
int ast_taskprocessor_push(struct ast_taskprocessor *tps, int (*task_exe)(void *datap), void *datap);
|
||||
|
||||
/*!
|
||||
* \brief Pop a task off the taskprocessor and execute it.
|
||||
* \param tps The taskprocessor from which to execute.
|
||||
* \retval 0 There is no further work to be done.
|
||||
* \retval 1 Tasks still remain in the taskprocessor queue.
|
||||
*/
|
||||
int ast_taskprocessor_execute(struct ast_taskprocessor *tps);
|
||||
|
||||
/*!
|
||||
* \brief Return the name of the taskprocessor singleton
|
||||
* \since 1.6.1
|
||||
|
Reference in New Issue
Block a user