summaryrefslogtreecommitdiff
path: root/main/threadpool.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2013-01-17 16:04:10 +0000
committerMark Michelson <mmichelson@digium.com>2013-01-17 16:04:10 +0000
commit84c50fde1fef6ec1a8930b9b6217bf3c3d99d2c7 (patch)
treeae8f3134845ad3dad6d063e848ddf2bcbb30a78f /main/threadpool.c
parent299f913928d34600a777b59211d125d2b0b53a6b (diff)
Address David's latest feedback on reviewboard:
* Add a max_size option for threadpools. Also added a test for this option. * Fixed comments to be more accurate and have fewer typos. * Updated copyright dates on new files. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379375 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/threadpool.c')
-rw-r--r--main/threadpool.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/main/threadpool.c b/main/threadpool.c
index e27b05345..adaf8a554 100644
--- a/main/threadpool.c
+++ b/main/threadpool.c
@@ -1,7 +1,7 @@
/*
* Asterisk -- An open source telephony toolkit.
*
- * Copyright (C) 2012, Digium, Inc.
+ * Copyright (C) 2012-2013, Digium, Inc.
*
* Mark Michelson <mmmichelson@digium.com>
*
@@ -24,6 +24,7 @@
#include "asterisk/astobj2.h"
#include "asterisk/utils.h"
+/* Needs to stay prime if increased */
#define THREAD_BUCKETS 89
/*!
@@ -494,6 +495,13 @@ static void grow(struct ast_threadpool *pool, int delta)
{
int i;
+ int current_size = ao2_container_count(pool->active_threads) +
+ ao2_container_count(pool->idle_threads);
+
+ if (pool->options.max_size && current_size + delta > pool->options.max_size) {
+ delta = pool->options.max_size - current_size;
+ }
+
ast_debug(3, "Increasing threadpool %s's size by %d\n",
ast_taskprocessor_name(pool->tps), delta);
@@ -788,7 +796,7 @@ static int queued_set_size(void *data)
struct ast_threadpool *pool = ssd->pool;
unsigned int num_threads = ssd->size;
- /* We don't count zombie threads as being "live when potentially resizing */
+ /* We don't count zombie threads as being "live" when potentially resizing */
unsigned int current_size = ao2_container_count(pool->active_threads) +
ao2_container_count(pool->idle_threads);
@@ -895,6 +903,9 @@ int ast_threadpool_push(struct ast_threadpool *pool, int (*task)(void *data), vo
void ast_threadpool_shutdown(struct ast_threadpool *pool)
{
+ if (!pool) {
+ return;
+ }
/* Shut down the taskprocessors and everything else just
* takes care of itself via the taskprocessor callbacks
*/