[svn-commits] dhubbard: branch group/taskprocessors r111951 - in /team/group/taskprocessors...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Mar 29 13:10:24 CDT 2008


Author: dhubbard
Date: Sat Mar 29 13:10:23 2008
New Revision: 111951

URL: http://svn.digium.com/view/asterisk?view=rev&rev=111951
Log:
fail to reference an existing taskprocessor if the requested processing function does not match the existing taskprocessor's _poll_function

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=111951&r1=111950&r2=111951
==============================================================================
--- team/group/taskprocessors/include/asterisk/taskprocessor.h (original)
+++ team/group/taskprocessors/include/asterisk/taskprocessor.h Sat Mar 29 13:10:23 2008
@@ -89,6 +89,8 @@
 	ast_mutex_t _taskprocessor_lock;
 	/*! \brief Taskprocesor thread run flag */
 	unsigned char _poll_thread_run;
+	/*! \brief Hold a pointer to the taskprocessing function */
+	void *(*_poll_function)(void*);
 	/*! \brief Taskprocessor statistics */
 	struct taskprocessor_singleton_stats *_stats;
 	/*! \brief private data for a taskprocessor */

Modified: team/group/taskprocessors/main/taskprocessor.c
URL: http://svn.digium.com/view/asterisk/team/group/taskprocessors/main/taskprocessor.c?view=diff&rev=111951&r1=111950&r2=111951
==============================================================================
--- team/group/taskprocessors/main/taskprocessor.c (original)
+++ team/group/taskprocessors/main/taskprocessor.c Sat Mar 29 13:10:23 2008
@@ -346,17 +346,12 @@
 	AST_LIST_TRAVERSE(&_taskprocessor_singletons, p, list) {
 		if (!strcasecmp(p->_name, name)) {
 			AST_LIST_UNLOCK(&_taskprocessor_singletons);
+			ast_debug(5, "taskprocessor_singleton \'%s\' already exists!.\n", p->_name);
+			if (p->_poll_function != ((custom_func)?custom_func:tps_default_processor_function)) {
+				ast_log(LOG_ERROR, "A taskprocessor \'%s\' already exists with a differing task processing function.\n", name);
+				return NULL;
+			}
 			ao2_ref(p, 1);
-			ast_debug(5, "taskprocessor_singleton \'%s\' already exists!.\n", p->_name);
-			/* a scenario here slightly worries me.  If a module calls ast_taskprocessor_reference(blah, 0) and then
- 			 * another module calls ast_taskprocessor_reference(blah, custom_func) then the custom_func is not going
- 			 * to be assigned to the taskprocessor because that name already exists with a different processing
- 			 * function.  We might want to check for that and return a NULL if someone requests a taskprocessor that
- 			 * already exists, but the processing function doesn't match.  In any case, this stuff is not happening
- 			 * dynamically and one would think that this scenario would be caught before a commit was made, but I'm
- 			 * pretty sure that stranger things have happened.
- 			 *
- 			 * In the meantime, if the processor thread already exists, return it without comparing processing functions. */
 			return p;
 		}
 	}
@@ -386,10 +381,13 @@
 		/* wake it up */
 		pthread_kill(p->_poll_thread, SIGURG);
 	} else {
-		/* create the thread.  This may seem silly, but it results in nicer 'core show threads' output */
+		/* The logic for creating the processor thread in the block below may seem silly, 
+		 * but doing it this way results in more useful 'core show threads' output */
 		if (custom_func) {
+			p->_poll_function = custom_func;
 			rc = ast_pthread_create(&p->_poll_thread, NULL, custom_func, p);
 		} else {
+			p->_poll_function = tps_default_processor_function;
 			rc = ast_pthread_create(&p->_poll_thread, NULL, tps_default_processor_function, p);
 		}
 		if (rc < 0) {




More information about the svn-commits mailing list