[svn-commits] mmichelson: branch mmichelson/threadpool r377805 - in /team/mmichelson/thread...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Dec 11 10:53:20 CST 2012


Author: mmichelson
Date: Tue Dec 11 10:53:16 2012
New Revision: 377805

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=377805
Log:
Some general cleanup, plus we now send state changes when threads activate.

This is now ready for review board, imo!


Modified:
    team/mmichelson/threadpool/include/asterisk/threadpool.h
    team/mmichelson/threadpool/main/threadpool.c

Modified: team/mmichelson/threadpool/include/asterisk/threadpool.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/include/asterisk/threadpool.h?view=diff&rev=377805&r1=377804&r2=377805
==============================================================================
--- team/mmichelson/threadpool/include/asterisk/threadpool.h (original)
+++ team/mmichelson/threadpool/include/asterisk/threadpool.h Tue Dec 11 10:53:16 2012
@@ -89,7 +89,7 @@
 	/*!
 	 * \brief Time limit in seconds for idle threads
 	 *
-	 * A time of 0 or less will mean an infinite timeout.
+	 * A time of 0 or less will mean no timeout.
 	 */
 	int idle_timeout;
 	/*!

Modified: team/mmichelson/threadpool/main/threadpool.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/main/threadpool.c?view=diff&rev=377805&r1=377804&r2=377805
==============================================================================
--- team/mmichelson/threadpool/main/threadpool.c (original)
+++ team/mmichelson/threadpool/main/threadpool.c Tue Dec 11 10:53:16 2012
@@ -435,7 +435,28 @@
 	return CMP_MATCH;
 }
 
-static void grow(struct ast_threadpool *pool, int delta);
+/*!
+ * \brief Add threads to the threadpool
+ *
+ * This function is called from the threadpool's control taskprocessor thread.
+ * \param pool The pool that is expanding
+ * \delta The number of threads to add to the pool
+ */
+static void grow(struct ast_threadpool *pool, int delta)
+{
+	int i;
+
+	ast_debug(1, "Going to increase threadpool size by %d\n", delta);
+
+	for (i = 0; i < delta; ++i) {
+		struct worker_thread *worker = worker_thread_alloc(pool);
+		if (!worker) {
+			return;
+		}
+		ao2_link(pool->active_threads, worker);
+		ao2_ref(worker, -1);
+	}
+}
 
 /*!
  * \brief Queued task called when tasks are pushed into the threadpool
@@ -451,15 +472,22 @@
 	struct task_pushed_data *tpd = data;
 	struct ast_threadpool *pool = tpd->pool;
 	int was_empty = tpd->was_empty;
+	int state_changed;
 
 	pool->listener->callbacks->task_pushed(pool, pool->listener, was_empty);
-	if (ao2_container_count(pool->idle_threads) == 0 && pool->options.auto_increment > 0) {
-		grow(pool, pool->options.auto_increment);
+	if (ao2_container_count(pool->idle_threads) == 0) {
+		if (pool->options.auto_increment > 0) {
+			grow(pool, pool->options.auto_increment);
+			state_changed = 1;
+		}
 	} else {
 		ao2_callback(pool->idle_threads, OBJ_UNLINK | OBJ_NOLOCK | OBJ_NODATA,
 				activate_thread, pool);
-	}	
-	threadpool_send_state_changed(pool);
+		state_changed = 1;
+	}
+	if (state_changed) {
+		threadpool_send_state_changed(pool);
+	}
 	ao2_ref(tpd, -1);
 	return 0;
 }
@@ -572,29 +600,6 @@
 };
 
 /*!
- * \brief Add threads to the threadpool
- *
- * This function is called from the threadpool's control taskprocessor thread.
- * \param pool The pool that is expanding
- * \delta The number of threads to add to the pool
- */
-static void grow(struct ast_threadpool *pool, int delta)
-{
-	int i;
-
-	ast_debug(1, "Going to increase threadpool size by %d\n", delta);
-
-	for (i = 0; i < delta; ++i) {
-		struct worker_thread *worker = worker_thread_alloc(pool);
-		if (!worker) {
-			return;
-		}
-		ao2_link(pool->active_threads, worker);
-		ao2_ref(worker, -1);
-	}
-}
-
-/*!
  * \brief ao2 callback to kill a set number of threads.
  *
  * Threads will be unlinked from the container as long as the
@@ -680,7 +685,7 @@
 	ao2_callback(pool->idle_threads, OBJ_UNLINK | OBJ_NOLOCK | OBJ_NODATA | OBJ_MULTIPLE,
 			kill_threads, &idle_threads_to_kill);
 
-	ast_debug(1, "Goign to kill off %d active threads\n", active_threads_to_zombify);
+	ast_debug(1, "Going to kill off %d active threads\n", active_threads_to_zombify);
 
 	ao2_callback_data(pool->active_threads, OBJ_UNLINK | OBJ_NOLOCK | OBJ_NODATA | OBJ_MULTIPLE,
 			zombify_threads, pool, &active_threads_to_zombify);




More information about the svn-commits mailing list