summaryrefslogtreecommitdiff
path: root/main/threadpool.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2012-12-11 16:34:00 +0000
committerMark Michelson <mmichelson@digium.com>2012-12-11 16:34:00 +0000
commit8760e32ae380f65420799c290f7b92d40cd7926c (patch)
tree21f110cf8fd84476baee7e0fea62f4776db12055 /main/threadpool.c
parent29fc1227839155658ca899cdfa179673c88e1ee2 (diff)
Add auto-increment option and accompanying test.
This allows for the threadpool to automatically grow if tasks are pushed to it and no idle threads are currently available. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377803 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/threadpool.c')
-rw-r--r--main/threadpool.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/main/threadpool.c b/main/threadpool.c
index 57520cf11..b3195fc4c 100644
--- a/main/threadpool.c
+++ b/main/threadpool.c
@@ -416,7 +416,7 @@ static struct task_pushed_data *task_pushed_data_alloc(struct ast_threadpool *po
/*!
* \brief Activate idle threads
*
- * This function always returns CMP_MATCH because all threads that this
+ * This function always returns CMP_MATCH because all workers that this
* function acts on need to be seen as matches so they are unlinked from the
* list of idle threads.
*
@@ -425,7 +425,7 @@ static struct task_pushed_data *task_pushed_data_alloc(struct ast_threadpool *po
* \param arg The pool where the worker belongs
* \retval CMP_MATCH
*/
-static int activate_threads(void *obj, void *arg, int flags)
+static int activate_thread(void *obj, void *arg, int flags)
{
struct worker_thread *worker = obj;
struct ast_threadpool *pool = arg;
@@ -435,6 +435,8 @@ static int activate_threads(void *obj, void *arg, int flags)
return CMP_MATCH;
}
+static void grow(struct ast_threadpool *pool, int delta);
+
/*!
* \brief Queued task called when tasks are pushed into the threadpool
*
@@ -451,8 +453,13 @@ static int queued_task_pushed(void *data)
int was_empty = tpd->was_empty;
pool->listener->callbacks->task_pushed(pool, pool->listener, was_empty);
- ao2_callback(pool->idle_threads, OBJ_UNLINK | OBJ_NOLOCK | OBJ_NODATA | OBJ_MULTIPLE,
- activate_threads, pool);
+ if (ao2_container_count(pool->idle_threads) == 0 && pool->options.auto_increment > 0) {
+ grow(pool, pool->options.auto_increment);
+ } else {
+ ao2_callback(pool->idle_threads, OBJ_UNLINK | OBJ_NOLOCK | OBJ_NODATA,
+ activate_thread, pool);
+ }
+ threadpool_send_state_changed(pool);
ao2_ref(tpd, -1);
return 0;
}