summaryrefslogtreecommitdiff
path: root/main/threadpool.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2012-12-10 04:08:29 +0000
committerMark Michelson <mmichelson@digium.com>2012-12-10 04:08:29 +0000
commit03d617040a1749c8efb90cc7d125583256e8cbb9 (patch)
treeff8feb293ee62748d3f70187896f3dacbba88066 /main/threadpool.c
parent955307ef9f6eb1cb19e285229d72e8ee8b0d3146 (diff)
Add safeguards to ensure we don't improperly access a destroyed taskprocessor.
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377556 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/threadpool.c')
-rw-r--r--main/threadpool.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/main/threadpool.c b/main/threadpool.c
index f1039f937..8d60f878b 100644
--- a/main/threadpool.c
+++ b/main/threadpool.c
@@ -93,6 +93,8 @@ struct ast_threadpool {
* that the threadpool had its state change.
*/
struct ast_taskprocessor *control_tps;
+ /*! True if the threadpool is in the processof shutting down */
+ int shutting_down;
};
/*!
@@ -266,7 +268,10 @@ static void threadpool_zombie_thread_dead(struct ast_threadpool *pool,
*/
static int threadpool_execute(struct ast_threadpool *pool)
{
- return ast_taskprocessor_execute(pool->tps);
+ if (!pool->shutting_down) {
+ return ast_taskprocessor_execute(pool->tps);
+ }
+ return 0;
}
/*!
@@ -745,7 +750,10 @@ struct ast_threadpool *ast_threadpool_create(struct ast_threadpool_listener *lis
int ast_threadpool_push(struct ast_threadpool *pool, int (*task)(void *data), void *data)
{
- return ast_taskprocessor_push(pool->tps, task, data);
+ if (!pool->shutting_down) {
+ return ast_taskprocessor_push(pool->tps, task, data);
+ }
+ return 0;
}
void ast_threadpool_shutdown(struct ast_threadpool *pool)
@@ -753,6 +761,7 @@ void ast_threadpool_shutdown(struct ast_threadpool *pool)
/* Shut down the taskprocessors and everything else just
* takes care of itself via the taskprocessor callbacks
*/
+ ast_atomic_fetchadd_int(&pool->shutting_down, +1);
ast_taskprocessor_unreference(pool->control_tps);
ast_taskprocessor_unreference(pool->tps);
}