[asterisk-commits] mmichelson: branch mmichelson/threadpool r377687 - in /team/mmichelson/thread...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 10 14:14:25 CST 2012


Author: mmichelson
Date: Mon Dec 10 14:14:23 2012
New Revision: 377687

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=377687
Log:
Solve the issue about the "CHANGE THIS" and "XXX CHANGE THIS XXX" taskprocessor names.

Unfortunately, this required a taskprocessor listener change that makes listener allocation
utterly silly. I'm going to change the scheme so that allocation of taskprocessor listeners
is done internally within taskprocessor code. This will make it parallel with threadpool
code, which is a good thing.


Modified:
    team/mmichelson/threadpool/include/asterisk/threadpool.h
    team/mmichelson/threadpool/main/taskprocessor.c
    team/mmichelson/threadpool/main/threadpool.c
    team/mmichelson/threadpool/tests/test_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=377687&r1=377686&r2=377687
==============================================================================
--- team/mmichelson/threadpool/include/asterisk/threadpool.h (original)
+++ team/mmichelson/threadpool/include/asterisk/threadpool.h Mon Dec 10 14:14:23 2012
@@ -113,12 +113,14 @@
  * This function creates a threadpool. Tasks may be pushed onto this thread pool
  * in and will be automatically acted upon by threads within the pool.
  *
+ * \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
  * \retval NULL Failed to create the threadpool
  * \retval non-NULL The newly-created threadpool
  */
-struct ast_threadpool *ast_threadpool_create(struct ast_threadpool_listener *listener,
+struct ast_threadpool *ast_threadpool_create(const char *name,
+		struct ast_threadpool_listener *listener,
 		int initial_size, const struct ast_threadpool_options *options);
 
 /*!

Modified: team/mmichelson/threadpool/main/taskprocessor.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/main/taskprocessor.c?view=diff&rev=377687&r1=377686&r2=377687
==============================================================================
--- team/mmichelson/threadpool/main/taskprocessor.c (original)
+++ team/mmichelson/threadpool/main/taskprocessor.c Mon Dec 10 14:14:23 2012
@@ -485,10 +485,6 @@
 		return NULL;
 	}
 	listener->callbacks = callbacks;
-	listener->private_data = listener->callbacks->alloc(listener);
-	if (!listener->private_data) {
-		return NULL;
-	}
 
 	ao2_ref(listener, +1);
 	return listener;
@@ -558,6 +554,11 @@
 
 	ao2_ref(p, +1);
 	listener->tps = p;
+
+	listener->private_data = listener->callbacks->alloc(listener);
+	if (!listener->private_data) {
+		return NULL;
+	}
 
 	if (!(ao2_link(tps_singletons, p))) {
 		ast_log(LOG_ERROR, "Failed to add taskprocessor '%s' to container\n", p->name);

Modified: team/mmichelson/threadpool/main/threadpool.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/main/threadpool.c?view=diff&rev=377687&r1=377686&r2=377687
==============================================================================
--- team/mmichelson/threadpool/main/threadpool.c (original)
+++ team/mmichelson/threadpool/main/threadpool.c Mon Dec 10 14:14:23 2012
@@ -349,8 +349,15 @@
 {
 	RAII_VAR(struct ast_threadpool *, pool,
 			ao2_alloc(sizeof(*pool), threadpool_destructor), ao2_cleanup);
-
-	pool->control_tps = ast_taskprocessor_get("CHANGE THIS", TPS_REF_DEFAULT);
+	struct ast_str *name = ast_str_create(64);
+
+	if (!name) {
+		return NULL;
+	}
+
+	ast_str_set(&name, 0, "%s-control", ast_taskprocessor_name(listener->tps));
+
+	pool->control_tps = ast_taskprocessor_get(ast_str_buffer(name), TPS_REF_DEFAULT);
 	if (!pool->control_tps) {
 		return NULL;
 	}
@@ -782,7 +789,8 @@
 	struct ast_threadpool_options options;
 };
 
-struct ast_threadpool *ast_threadpool_create(struct ast_threadpool_listener *listener,
+struct ast_threadpool *ast_threadpool_create(const char *name,
+		struct ast_threadpool_listener *listener,
 		int initial_size, const struct ast_threadpool_options *options)
 {
 	struct ast_threadpool *pool;
@@ -795,7 +803,7 @@
 		return NULL;
 	}
 
-	tps = ast_taskprocessor_create_with_listener("XXX CHANGE THIS XXX", tps_listener);
+	tps = ast_taskprocessor_create_with_listener(name, tps_listener);
 
 	if (!tps) {
 		return NULL;

Modified: team/mmichelson/threadpool/tests/test_threadpool.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/tests/test_threadpool.c?view=diff&rev=377687&r1=377686&r2=377687
==============================================================================
--- team/mmichelson/threadpool/tests/test_threadpool.c (original)
+++ team/mmichelson/threadpool/tests/test_threadpool.c Mon Dec 10 14:14:23 2012
@@ -287,7 +287,7 @@
 
 	switch (cmd) {
 	case TEST_INIT:
-		info->name = "threadpool_push";
+		info->name = "push";
 		info->category = "/main/threadpool/";
 		info->summary = "Test task";
 		info->description =
@@ -302,7 +302,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	pool = ast_threadpool_create(listener, 0, &options);
+	pool = ast_threadpool_create(info->name, listener, 0, &options);
 	if (!pool) {
 		goto end;
 	}
@@ -340,7 +340,7 @@
 
 	switch (cmd) {
 	case TEST_INIT:
-		info->name = "threadpool_thread_creation";
+		info->name = "thread_creation";
 		info->category = "/main/threadpool/";
 		info->summary = "Test threadpool thread creation";
 		info->description =
@@ -356,7 +356,7 @@
 	}
 	tld = listener->private_data;
 
-	pool = ast_threadpool_create(listener, 0, &options);
+	pool = ast_threadpool_create(info->name, listener, 0, &options);
 	if (!pool) {
 		goto end;
 	}
@@ -389,7 +389,7 @@
 
 	switch (cmd) {
 	case TEST_INIT:
-		info->name = "threadpool_thread_destruction";
+		info->name = "thread_destruction";
 		info->category = "/main/threadpool/";
 		info->summary = "Test threadpool thread destruction";
 		info->description =
@@ -405,7 +405,7 @@
 	}
 	tld = listener->private_data;
 
-	pool = ast_threadpool_create(listener, 0, &options);
+	pool = ast_threadpool_create(info->name, listener, 0, &options);
 	if (!pool) {
 		goto end;
 	}
@@ -447,7 +447,7 @@
 
 	switch (cmd) {
 	case TEST_INIT:
-		info->name = "threadpool_thread_timeout";
+		info->name = "thread_timeout";
 		info->category = "/main/threadpool/";
 		info->summary = "Test threadpool thread timeout";
 		info->description =
@@ -463,7 +463,7 @@
 	}
 	tld = listener->private_data;
 
-	pool = ast_threadpool_create(listener, 0, &options);
+	pool = ast_threadpool_create(info->name, listener, 0, &options);
 	if (!pool) {
 		goto end;
 	}
@@ -509,7 +509,7 @@
 
 	switch (cmd) {
 	case TEST_INIT:
-		info->name = "threadpool_one_task_one_thread";
+		info->name = "one_task_one_thread";
 		info->category = "/main/threadpool/";
 		info->summary = "Test a single task with a single thread";
 		info->description =
@@ -525,7 +525,7 @@
 	}
 	tld = listener->private_data;
 
-	pool = ast_threadpool_create(listener, 0, &options);
+	pool = ast_threadpool_create(info->name, listener, 0, &options);
 	if (!pool) {
 		goto end;
 	}
@@ -585,7 +585,7 @@
 
 	switch (cmd) {
 	case TEST_INIT:
-		info->name = "threadpool_one_thread_one_task";
+		info->name = "one_thread_one_task";
 		info->category = "/main/threadpool/";
 		info->summary = "Test a single thread with a single task";
 		info->description =
@@ -601,7 +601,7 @@
 	}
 	tld = listener->private_data;
 
-	pool = ast_threadpool_create(listener, 0, &options);
+	pool = ast_threadpool_create(info->name, listener, 0, &options);
 	if (!pool) {
 		goto end;
 	}
@@ -664,7 +664,7 @@
 
 	switch (cmd) {
 	case TEST_INIT:
-		info->name = "threadpool_one_thread_multiple_tasks";
+		info->name = "one_thread_multiple_tasks";
 		info->category = "/main/threadpool/";
 		info->summary = "Test a single thread with multiple tasks";
 		info->description =
@@ -680,7 +680,7 @@
 	}
 	tld = listener->private_data;
 
-	pool = ast_threadpool_create(listener, 0, &options);
+	pool = ast_threadpool_create(info->name, listener, 0, &options);
 	if (!pool) {
 		goto end;
 	}
@@ -755,7 +755,7 @@
 
 	switch (cmd) {
 	case TEST_INIT:
-		info->name = "threadpool_reactivation";
+		info->name = "reactivation";
 		info->category = "/main/threadpool/";
 		info->summary = "Test that a threadpool reactivates when work is added";
 		info->description =
@@ -773,7 +773,7 @@
 	}
 	tld = listener->private_data;
 
-	pool = ast_threadpool_create(listener, 0, &options);
+	pool = ast_threadpool_create(info->name, listener, 0, &options);
 	if (!pool) {
 		goto end;
 	}
@@ -917,7 +917,7 @@
 
 	switch (cmd) {
 	case TEST_INIT:
-		info->name = "threadpool_task_distribution";
+		info->name = "task_distribution";
 		info->category = "/main/threadpool/";
 		info->summary = "Test that tasks are evenly distributed to threads";
 		info->description =
@@ -934,7 +934,7 @@
 	}
 	tld = listener->private_data;
 
-	pool = ast_threadpool_create(listener, 0, &options);
+	pool = ast_threadpool_create(info->name, listener, 0, &options);
 	if (!pool) {
 		goto end;
 	}
@@ -1005,7 +1005,7 @@
 
 	switch (cmd) {
 	case TEST_INIT:
-		info->name = "threadpool_more_destruction";
+		info->name = "more_destruction";
 		info->category = "/main/threadpool/";
 		info->summary = "Test that threads are destroyed as expected";
 		info->description =
@@ -1024,7 +1024,7 @@
 	}
 	tld = listener->private_data;
 
-	pool = ast_threadpool_create(listener, 0, &options);
+	pool = ast_threadpool_create(info->name, listener, 0, &options);
 	if (!pool) {
 		goto end;
 	}




More information about the asterisk-commits mailing list