[asterisk-commits] dhubbard: branch group/taskprocessors r114111 - in /team/group/taskprocessors...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 14 11:16:19 CDT 2008


Author: dhubbard
Date: Mon Apr 14 11:16:19 2008
New Revision: 114111

URL: http://svn.digium.com/view/asterisk?view=rev&rev=114111
Log:
remove assert stuff

Modified:
    team/group/taskprocessors/include/asterisk/taskprocessor.h
    team/group/taskprocessors/main/taskprocessor.c

Modified: team/group/taskprocessors/include/asterisk/taskprocessor.h
URL: http://svn.digium.com/view/asterisk/team/group/taskprocessors/include/asterisk/taskprocessor.h?view=diff&rev=114111&r1=114110&r2=114111
==============================================================================
--- team/group/taskprocessors/include/asterisk/taskprocessor.h (original)
+++ team/group/taskprocessors/include/asterisk/taskprocessor.h Mon Apr 14 11:16:19 2008
@@ -63,22 +63,58 @@
 /*! \brief Initialize the taskprocessor subsystem */
 int ast_tps_init(void);
 
-/*! \brief Allocate ast_task object */
+/*! \brief Allocate and initialize a task structure.
+ * \param task_exe The task handling function that will be called when this task is popped
+ * off the taskprocessor queue and executed.
+ * \param datap The data to pass to the task_exe function when the task is executed
+ * \param src The calling function name (this will become DEBUG only)
+ * \return A task structure ready to be queued into a taskprocessor, NULL on error */
 struct ast_task *ast_task_alloc(int (*task_exe)(void *datap), void *datap, char *src);
-/*! \brief Release ast_task resources */
+
+/*! \brief Free the task resources
+ * \note This function does not free any memory pointed to by the data pointer.  It is
+ * the responsibility of the task handling function to free any resources managed by
+ * a task's data pointer.
+ * \param task The task to free
+ * \return zero */
 int ast_task_free(struct ast_task *task);
 
-/*! \brief Obtain a taskprocessor reference */
+/*! \brief Get a reference to a taskprocessor with the specified name; create a taskprocessor
+ * if one with the specified name does not already exist.  The default processing function
+ * can be overridden using the second argument, custom_func, at the time of taskprocessor creation.
+ * The default behavior of instantiating a taskprocessor if one does not already exist can be
+ * disabled by specifying the TPS_REF_IF_EXISTS reference type as the third argument to ast_taskprocessor_get().
+ * \param name The name of the taskprocessor
+ * \param custom_func Use 0 by default or specify a custom taskprocessor thread function
+ * \param create Use 0 by default or specify TPS_REF_IF_EXISTS to return NULL if the taskprocessor does 
+ * not already exist
+ * return A pointer to a reference counted taskprocessor under normal conditions, or NULL if the
+ * TPS_REF_IF_EXISTS reference type is specified */
 struct ast_taskprocessor *ast_taskprocessor_get(char *name, void *(*custom_func)(void*), enum ast_tps_reftype create);
-/*! \brief Release a taskprocessor reference */
+
+/*! \brief Unreference the specified taskprocessor and its reference count will decrement.
+ * taskprocessors use astobj2 and will destroy themselves when their reference count reaches zero.
+ * \param tps taskprocessor to unreference
+ * \return NULL */
 void *ast_taskprocessor_unreference(struct ast_taskprocessor *tps);
 
-/*! \brief Push a task on the taskprocessor */
+/*! \brief Push a task into the specified taskprocessor queue and signal the taskprocessor thread
+ * \param tps The taskprocessor structure
+ * \param t The task to push into the taskprocessor queue
+ * \return zero on success, -1 on failure */
 int ast_taskprocessor_push(struct ast_taskprocessor *tps, struct ast_task *t);
-/*! \brief Pop the front task off the taskprocessor queue and return it to the calling function */
+
+/*! \brief If a task is in the taskprocessor queue it will be popped from the queue
+ * and its address will be returned.  This function returns NULL if the queue is empty.
+ * \param tps The taskprocessor structure
+ * \return A task pointer if the queue is not empty, NULL when the queue is empty. */
 struct ast_task *ast_taskprocessor_pop(struct ast_taskprocessor *tps);
-/*! \brief Return the number of ast_task elements currently in the taskprocessor queue */
+
+/*! \brief Return the number of tasks waiting in the taskprocessor queue
+ * \param tps taskprocessor to return queue depth
+ * \return depth on success, -1 on error */
 int ast_taskprocessor_depth(struct ast_taskprocessor *tps);
+
 /*! \brief Return the name of the taskprocessor singleton */
 char * ast_taskprocessor_name(struct ast_taskprocessor *tps);
 #endif

Modified: team/group/taskprocessors/main/taskprocessor.c
URL: http://svn.digium.com/view/asterisk/team/group/taskprocessors/main/taskprocessor.c?view=diff&rev=114111&r1=114110&r2=114111
==============================================================================
--- team/group/taskprocessors/main/taskprocessor.c (original)
+++ team/group/taskprocessors/main/taskprocessor.c Mon Apr 14 11:16:19 2008
@@ -31,7 +31,6 @@
 #include "asterisk/taskprocessor.h"
 #include "signal.h"
 #include "sys/time.h"
-#include "assert.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
@@ -371,8 +370,8 @@
 static struct ast_taskprocessor *tps_default_constructor(void)
 {
 	struct ast_taskprocessor *tps;
-	tps = ao2_alloc(sizeof(*tps), tps_taskprocessor_destroy);
-	if (!tps) {
+	
+	if (!(tps = ao2_alloc(sizeof(*tps), tps_taskprocessor_destroy))) {
 		return NULL;
 	}
 	ast_cond_init(&tps->poll_cond, NULL);
@@ -437,12 +436,12 @@
 	p->name = ast_strdup(name);
 	p->poll_thread_run = 1;
 
-	/* reducing the ast_pthread_create() blocks below into a single block, to something like:
+	/* compressing the 'if (custom_func)' blocks below into a single block, using something like:
 	 *
 	 * 		ast_pthread_create(&stuff, NULL, (custom_func)?eeep:mooo, p);
 	 *
-	 * will result in uglier 'core show threads' output and you won't know if the default
-	 * processing function was used or not. */
+	 * will result in uglier and less useful 'core show threads' output because you won't know if the default
+	 * processing function was used or not and the CLI output is going to make you sad */
 	if (custom_func) {
 		p->poll_function = custom_func;
 		rc = ast_pthread_create(&p->poll_thread, NULL, custom_func, p);
@@ -482,11 +481,17 @@
 {
 	struct ast_taskprocessor *t = tps;
 	
-	assert(tps);
+	if (!tps) {
+		ast_log(LOG_ERROR, "missing taskprocessor\n");
+		return;
+	}
 	ast_debug(5, "destroying taskprocessor \'%s\'\n", t->name);
+	/* take the taskprocessor out of the singleton container */	
+	ast_mutex_lock(&tps_marshall);
 	ao2_unlink(tps_singletons, t);
-
+	ast_mutex_unlock(&tps_marshall);
 	ast_debug(5, "taskprocessor \'%s\' unlinked from tps_singletons\n", t->name);
+	/* kill it */	
 	ast_mutex_lock(&t->taskprocessor_lock);
 	t->poll_thread_run = 0;
 	ast_cond_signal(&t->poll_cond);
@@ -508,8 +513,10 @@
  */
 int ast_taskprocessor_push(struct ast_taskprocessor *tps, struct ast_task *t)
 {
-	assert(t);
-	assert(tps);
+	if (!tps || !t) {
+		ast_log(LOG_ERROR, "missing \'%s\'\n", (tps)?"task":"taskprocessor");
+		return -1;
+	}
 	ast_mutex_lock(&tps->taskprocessor_lock);
 	AST_LIST_INSERT_TAIL(&tps->queue, t, list);
 	tps->queue_size++;
@@ -526,8 +533,10 @@
 {
 	struct ast_task *t;
 
-	assert(tps);
-	assert(tps->name);
+	if (!tps) {
+		ast_log(LOG_ERROR, "missing taskprocessor\n");
+		return NULL;
+	}
 	ast_mutex_lock(&tps->taskprocessor_lock);
 	if ((t = AST_LIST_REMOVE_HEAD(&tps->queue, list))) {
 		tps->queue_size--;
@@ -542,11 +551,11 @@
  */
 int ast_taskprocessor_depth(struct ast_taskprocessor *tps)
 {
-	int size;
-
-	assert(tps);
-	assert(tps->name);
-	size = tps->queue_size;
+	int size = -1;
+
+	if (tps) {
+		size = tps->queue_size;
+	}
 	return size;
 }
 




More information about the asterisk-commits mailing list