mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-20 12:20:12 +00:00
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
This commit is contained in:
@@ -93,6 +93,8 @@ struct ast_threadpool {
|
|||||||
* that the threadpool had its state change.
|
* that the threadpool had its state change.
|
||||||
*/
|
*/
|
||||||
struct ast_taskprocessor *control_tps;
|
struct ast_taskprocessor *control_tps;
|
||||||
|
/*! True if the threadpool is in the processof shutting down */
|
||||||
|
int shutting_down;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -266,8 +268,11 @@ static void threadpool_zombie_thread_dead(struct ast_threadpool *pool,
|
|||||||
*/
|
*/
|
||||||
static int threadpool_execute(struct ast_threadpool *pool)
|
static int threadpool_execute(struct ast_threadpool *pool)
|
||||||
{
|
{
|
||||||
|
if (!pool->shutting_down) {
|
||||||
return ast_taskprocessor_execute(pool->tps);
|
return ast_taskprocessor_execute(pool->tps);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Destroy a threadpool's components.
|
* \brief Destroy a threadpool's components.
|
||||||
@@ -745,14 +750,18 @@ 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)
|
int ast_threadpool_push(struct ast_threadpool *pool, int (*task)(void *data), void *data)
|
||||||
{
|
{
|
||||||
|
if (!pool->shutting_down) {
|
||||||
return ast_taskprocessor_push(pool->tps, task, data);
|
return ast_taskprocessor_push(pool->tps, task, data);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void ast_threadpool_shutdown(struct ast_threadpool *pool)
|
void ast_threadpool_shutdown(struct ast_threadpool *pool)
|
||||||
{
|
{
|
||||||
/* Shut down the taskprocessors and everything else just
|
/* Shut down the taskprocessors and everything else just
|
||||||
* takes care of itself via the taskprocessor callbacks
|
* 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->control_tps);
|
||||||
ast_taskprocessor_unreference(pool->tps);
|
ast_taskprocessor_unreference(pool->tps);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user