Make the initial size of the threadpool part of the options passed in.

git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379123 65c4cc65-6c06-0410-ace0-fbb531ad65f3
changes/78/78/1
Mark Michelson 12 years ago
parent edc2e4dac0
commit c6bc51ef28

@ -102,6 +102,16 @@ struct ast_threadpool_options {
* to control threadpool growth yourself via your listener.
*/
int auto_increment;
/*!
* \brief Number of threads the pool will start with
*
* When the threadpool is allocated, it will immediately size
* itself to have this number of threads in it.
*
* Zero is a valid value if the threadpool should start
* without any threads allocated.
*/
int initial_size;
};
/*!
@ -126,13 +136,13 @@ struct ast_threadpool_listener *ast_threadpool_listener_alloc(
*
* \param name The name for the threadpool
* \param listener The listener the threadpool will notify of changes
* \param initial_size The number of threads for the pool to start with
* \param options The behavioral options for this threadpool
* \retval NULL Failed to create the threadpool
* \retval non-NULL The newly-created threadpool
*/
struct ast_threadpool *ast_threadpool_create(const char *name,
struct ast_threadpool_listener *listener,
int initial_size, const struct ast_threadpool_options *options);
const struct ast_threadpool_options *options);
/*!
* \brief Set the number of threads for the thread pool

@ -828,7 +828,7 @@ struct pool_options_pair {
struct ast_threadpool *ast_threadpool_create(const char *name,
struct ast_threadpool_listener *listener,
int initial_size, const struct ast_threadpool_options *options)
const struct ast_threadpool_options *options)
{
struct ast_taskprocessor *tps;
RAII_VAR(struct ast_taskprocessor_listener *, tps_listener, NULL, ao2_cleanup);
@ -858,7 +858,7 @@ struct ast_threadpool *ast_threadpool_create(const char *name,
ao2_ref(listener, +1);
pool->listener = listener;
}
ast_threadpool_set_size(pool, initial_size);
ast_threadpool_set_size(pool, pool->options.initial_size);
ao2_ref(pool, +1);
return pool;
}

@ -283,6 +283,7 @@ AST_TEST_DEFINE(threadpool_push)
.version = AST_THREADPOOL_OPTIONS_VERSION,
.idle_timeout = 0,
.auto_increment = 0,
.initial_size = 0,
};
switch (cmd) {
@ -306,7 +307,7 @@ AST_TEST_DEFINE(threadpool_push)
goto end;
}
pool = ast_threadpool_create(info->name, listener, 0, &options);
pool = ast_threadpool_create(info->name, listener, &options);
if (!pool) {
goto end;
}
@ -342,6 +343,7 @@ AST_TEST_DEFINE(threadpool_initial_threads)
.version = AST_THREADPOOL_OPTIONS_VERSION,
.idle_timeout = 0,
.auto_increment = 0,
.initial_size = 3,
};
switch (cmd) {
@ -367,7 +369,7 @@ AST_TEST_DEFINE(threadpool_initial_threads)
goto end;
}
pool = ast_threadpool_create(info->name, listener, 3, &options);
pool = ast_threadpool_create(info->name, listener, &options);
if (!pool) {
goto end;
}
@ -394,6 +396,7 @@ AST_TEST_DEFINE(threadpool_thread_creation)
.version = AST_THREADPOOL_OPTIONS_VERSION,
.idle_timeout = 0,
.auto_increment = 0,
.initial_size = 0,
};
switch (cmd) {
@ -418,7 +421,7 @@ AST_TEST_DEFINE(threadpool_thread_creation)
goto end;
}
pool = ast_threadpool_create(info->name, listener, 0, &options);
pool = ast_threadpool_create(info->name, listener, &options);
if (!pool) {
goto end;
}
@ -449,6 +452,7 @@ AST_TEST_DEFINE(threadpool_thread_destruction)
.version = AST_THREADPOOL_OPTIONS_VERSION,
.idle_timeout = 0,
.auto_increment = 0,
.initial_size = 0,
};
switch (cmd) {
@ -473,7 +477,7 @@ AST_TEST_DEFINE(threadpool_thread_destruction)
goto end;
}
pool = ast_threadpool_create(info->name, listener, 0, &options);
pool = ast_threadpool_create(info->name, listener, &options);
if (!pool) {
goto end;
}
@ -513,6 +517,7 @@ AST_TEST_DEFINE(threadpool_thread_timeout)
.version = AST_THREADPOOL_OPTIONS_VERSION,
.idle_timeout = 2,
.auto_increment = 0,
.initial_size = 0,
};
switch (cmd) {
@ -537,7 +542,7 @@ AST_TEST_DEFINE(threadpool_thread_timeout)
goto end;
}
pool = ast_threadpool_create(info->name, listener, 0, &options);
pool = ast_threadpool_create(info->name, listener, &options);
if (!pool) {
goto end;
}
@ -581,6 +586,7 @@ AST_TEST_DEFINE(threadpool_one_task_one_thread)
.version = AST_THREADPOOL_OPTIONS_VERSION,
.idle_timeout = 0,
.auto_increment = 0,
.initial_size = 0,
};
switch (cmd) {
@ -605,7 +611,7 @@ AST_TEST_DEFINE(threadpool_one_task_one_thread)
goto end;
}
pool = ast_threadpool_create(info->name, listener, 0, &options);
pool = ast_threadpool_create(info->name, listener, &options);
if (!pool) {
goto end;
}
@ -663,6 +669,7 @@ AST_TEST_DEFINE(threadpool_one_thread_one_task)
.version = AST_THREADPOOL_OPTIONS_VERSION,
.idle_timeout = 0,
.auto_increment = 0,
.initial_size = 0,
};
switch (cmd) {
@ -687,7 +694,7 @@ AST_TEST_DEFINE(threadpool_one_thread_one_task)
goto end;
}
pool = ast_threadpool_create(info->name, listener, 0, &options);
pool = ast_threadpool_create(info->name, listener, &options);
if (!pool) {
goto end;
}
@ -747,6 +754,7 @@ AST_TEST_DEFINE(threadpool_one_thread_multiple_tasks)
.version = AST_THREADPOOL_OPTIONS_VERSION,
.idle_timeout = 0,
.auto_increment = 0,
.initial_size = 0,
};
switch (cmd) {
@ -771,7 +779,7 @@ AST_TEST_DEFINE(threadpool_one_thread_multiple_tasks)
goto end;
}
pool = ast_threadpool_create(info->name, listener, 0, &options);
pool = ast_threadpool_create(info->name, listener, &options);
if (!pool) {
goto end;
}
@ -845,6 +853,7 @@ AST_TEST_DEFINE(threadpool_auto_increment)
.version = AST_THREADPOOL_OPTIONS_VERSION,
.idle_timeout = 0,
.auto_increment = 3,
.initial_size = 0,
};
switch (cmd) {
@ -871,7 +880,7 @@ AST_TEST_DEFINE(threadpool_auto_increment)
goto end;
}
pool = ast_threadpool_create(info->name, listener, 0, &options);
pool = ast_threadpool_create(info->name, listener, &options);
if (!pool) {
goto end;
}
@ -960,6 +969,7 @@ AST_TEST_DEFINE(threadpool_reactivation)
.version = AST_THREADPOOL_OPTIONS_VERSION,
.idle_timeout = 0,
.auto_increment = 0,
.initial_size = 0,
};
switch (cmd) {
@ -986,7 +996,7 @@ AST_TEST_DEFINE(threadpool_reactivation)
goto end;
}
pool = ast_threadpool_create(info->name, listener, 0, &options);
pool = ast_threadpool_create(info->name, listener, &options);
if (!pool) {
goto end;
}
@ -1128,6 +1138,7 @@ AST_TEST_DEFINE(threadpool_task_distribution)
.version = AST_THREADPOOL_OPTIONS_VERSION,
.idle_timeout = 0,
.auto_increment = 0,
.initial_size = 0,
};
switch (cmd) {
@ -1153,7 +1164,7 @@ AST_TEST_DEFINE(threadpool_task_distribution)
goto end;
}
pool = ast_threadpool_create(info->name, listener, 0, &options);
pool = ast_threadpool_create(info->name, listener, &options);
if (!pool) {
goto end;
}
@ -1222,6 +1233,7 @@ AST_TEST_DEFINE(threadpool_more_destruction)
.version = AST_THREADPOOL_OPTIONS_VERSION,
.idle_timeout = 0,
.auto_increment = 0,
.initial_size = 0,
};
switch (cmd) {
@ -1249,7 +1261,7 @@ AST_TEST_DEFINE(threadpool_more_destruction)
goto end;
}
pool = ast_threadpool_create(info->name, listener, 0, &options);
pool = ast_threadpool_create(info->name, listener, &options);
if (!pool) {
goto end;
}

Loading…
Cancel
Save