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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 15 14:15:04 CST 2013


Author: mmichelson
Date: Tue Jan 15 14:15:00 2013
New Revision: 379124

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379124
Log:
Address further review feedback from David Lee.

* Clarify some documentation
* Change copyright date of taskprocessor files
* Address potential issue of creating taskprocessor with listener if
  taskprocessor with that name exists already


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

Modified: team/mmichelson/threadpool/include/asterisk/taskprocessor.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/include/asterisk/taskprocessor.h?view=diff&rev=379124&r1=379123&r2=379124
==============================================================================
--- team/mmichelson/threadpool/include/asterisk/taskprocessor.h (original)
+++ team/mmichelson/threadpool/include/asterisk/taskprocessor.h Tue Jan 15 14:15:00 2013
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 2007-2008, Digium, Inc.
+ * Copyright (C) 2007-2013, Digium, Inc.
  *
  * Dwayne M. Hubbard <dhubbard at digium.com>
  *
@@ -22,7 +22,7 @@
  *
  * \author Dwayne M. Hubbard <dhubbard at digium.com>
  *
- * \note A taskprocessor is a named singleton containing a task queue that
+ * \note A taskprocessor is a named object containing a task queue that
  * serializes tasks pushed into it by [a] module(s) that reference the taskprocessor.
  * A taskprocessor is created the first time its name is requested via the
  * ast_taskprocessor_get() function or the ast_taskprocessor_create_with_listener()

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=379124&r1=379123&r2=379124
==============================================================================
--- team/mmichelson/threadpool/include/asterisk/threadpool.h (original)
+++ team/mmichelson/threadpool/include/asterisk/threadpool.h Tue Jan 15 14:15:00 2013
@@ -135,7 +135,7 @@
  * 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 listener The listener the threadpool will notify of changes. Can be NULL.
  * \param options The behavioral options for this threadpool
  * \retval NULL Failed to create the threadpool
  * \retval non-NULL The newly-created threadpool

Modified: team/mmichelson/threadpool/main/taskprocessor.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/main/taskprocessor.c?view=diff&rev=379124&r1=379123&r2=379124
==============================================================================
--- team/mmichelson/threadpool/main/taskprocessor.c (original)
+++ team/mmichelson/threadpool/main/taskprocessor.c Tue Jan 15 14:15:00 2013
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 2007-2008, Digium, Inc.
+ * Copyright (C) 2007-2013, Digium, Inc.
  *
  * Dwayne M. Hubbard <dhubbard at digium.com>
  *
@@ -487,56 +487,10 @@
 	return pvt;
 }
 
-/* Provide a reference to a taskprocessor.  Create the taskprocessor if necessary, but don't
- * create the taskprocessor if we were told via ast_tps_options to return a reference only
- * if it already exists */
-struct ast_taskprocessor *ast_taskprocessor_get(const char *name, enum ast_tps_options create)
-{
-	struct ast_taskprocessor *p;
-	struct ast_taskprocessor_listener *listener;
-	struct default_taskprocessor_listener_pvt *pvt;
-
-	if (ast_strlen_zero(name)) {
-		ast_log(LOG_ERROR, "requesting a nameless taskprocessor!!!\n");
-		return NULL;
-	}
-	p = ao2_find(tps_singletons, name, OBJ_KEY);
-	if (p) {
-		return p;
-	}
-	if (create & TPS_REF_IF_EXISTS) {
-		/* calling function does not want a new taskprocessor to be created if it doesn't already exist */
-		return NULL;
-	}
-	/* Create a new taskprocessor. Start by creating a default listener */
-	pvt = default_listener_pvt_alloc();
-	if (!pvt) {
-		return NULL;
-	}
-	listener = ast_taskprocessor_listener_alloc(&default_listener_callbacks, pvt);
-	if (!listener) {
-		default_listener_pvt_destroy(pvt);
-		return NULL;
-	}
-
-	p = ast_taskprocessor_create_with_listener(name, listener);
-	if (!p) {
-		default_listener_pvt_destroy(pvt);
-		ao2_ref(listener, -1);
-		return NULL;
-	}
-
-	/* Unref listener here since the taskprocessor has gained a reference to the listener */
-	ao2_ref(listener, -1);
-	return p;
-
-}
-
-struct ast_taskprocessor *ast_taskprocessor_create_with_listener(const char *name, struct ast_taskprocessor_listener *listener)
+static struct ast_taskprocessor *__allocate_taskprocessor(const char *name, struct ast_taskprocessor_listener *listener)
 {
 	RAII_VAR(struct ast_taskprocessor *, p,
-			ao2_alloc(sizeof(*p), tps_taskprocessor_destroy),
-			ao2_cleanup);
+			ao2_alloc(sizeof(*p), tps_taskprocessor_destroy), ao2_cleanup);
 
 	if (!p) {
 		ast_log(LOG_WARNING, "failed to create taskprocessor '%s'\n", name);
@@ -574,6 +528,63 @@
 	 */
 	ao2_ref(p, +1);
 	return p;
+
+}
+
+/* Provide a reference to a taskprocessor.  Create the taskprocessor if necessary, but don't
+ * create the taskprocessor if we were told via ast_tps_options to return a reference only
+ * if it already exists */
+struct ast_taskprocessor *ast_taskprocessor_get(const char *name, enum ast_tps_options create)
+{
+	struct ast_taskprocessor *p;
+	struct ast_taskprocessor_listener *listener;
+	struct default_taskprocessor_listener_pvt *pvt;
+
+	if (ast_strlen_zero(name)) {
+		ast_log(LOG_ERROR, "requesting a nameless taskprocessor!!!\n");
+		return NULL;
+	}
+	p = ao2_find(tps_singletons, name, OBJ_KEY);
+	if (p) {
+		return p;
+	}
+	if (create & TPS_REF_IF_EXISTS) {
+		/* calling function does not want a new taskprocessor to be created if it doesn't already exist */
+		return NULL;
+	}
+	/* Create a new taskprocessor. Start by creating a default listener */
+	pvt = default_listener_pvt_alloc();
+	if (!pvt) {
+		return NULL;
+	}
+	listener = ast_taskprocessor_listener_alloc(&default_listener_callbacks, pvt);
+	if (!listener) {
+		default_listener_pvt_destroy(pvt);
+		return NULL;
+	}
+
+	p = __allocate_taskprocessor(name, listener);
+	if (!p) {
+		default_listener_pvt_destroy(pvt);
+		ao2_ref(listener, -1);
+		return NULL;
+	}
+
+	/* Unref listener here since the taskprocessor has gained a reference to the listener */
+	ao2_ref(listener, -1);
+	return p;
+
+}
+
+struct ast_taskprocessor *ast_taskprocessor_create_with_listener(const char *name, struct ast_taskprocessor_listener *listener)
+{
+	struct ast_taskprocessor *p = ao2_find(tps_singletons, name, OBJ_KEY);
+
+	if (p) {
+		ast_taskprocessor_unreference(p);
+		return NULL;
+	}
+	return __allocate_taskprocessor(name, listener);
 }
 
 /* decrement the taskprocessor reference count and unlink from the container if necessary */

Modified: team/mmichelson/threadpool/main/threadpool.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/main/threadpool.c?view=diff&rev=379124&r1=379123&r2=379124
==============================================================================
--- team/mmichelson/threadpool/main/threadpool.c (original)
+++ team/mmichelson/threadpool/main/threadpool.c Tue Jan 15 14:15:00 2013
@@ -613,7 +613,9 @@
 {
 	struct ast_threadpool *pool = listener->user_data;
 
-	pool->listener->callbacks->shutdown(pool->listener);
+	if (pool->listener && pool->listener->callbacks->shutdown) {
+		pool->listener->callbacks->shutdown(pool->listener);
+	}
 	ao2_cleanup(pool->active_threads);
 	ao2_cleanup(pool->idle_threads);
 	ao2_cleanup(pool->zombie_threads);




More information about the asterisk-commits mailing list