[asterisk-commits] mmichelson: branch mmichelson/threadpool r377556 - /team/mmichelson/threadpoo...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Dec 9 22:08:32 CST 2012


Author: mmichelson
Date: Sun Dec  9 22:08:29 2012
New Revision: 377556

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=377556
Log:
Add safeguards to ensure we don't improperly access a destroyed taskprocessor.


Modified:
    team/mmichelson/threadpool/main/threadpool.c

Modified: team/mmichelson/threadpool/main/threadpool.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/main/threadpool.c?view=diff&rev=377556&r1=377555&r2=377556
==============================================================================
--- team/mmichelson/threadpool/main/threadpool.c (original)
+++ team/mmichelson/threadpool/main/threadpool.c Sun Dec  9 22:08:29 2012
@@ -93,6 +93,8 @@
 	 * 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 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 @@
 
 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 @@
 	/* 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);
 }




More information about the asterisk-commits mailing list