[asterisk-commits] dhubbard: branch group/taskprocessors r112561 - /team/group/taskprocessors/main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 2 20:42:07 CDT 2008
Author: dhubbard
Date: Wed Apr 2 20:42:06 2008
New Revision: 112561
URL: http://svn.digium.com/view/asterisk?view=rev&rev=112561
Log:
getting prepared for ao2_containers
Modified:
team/group/taskprocessors/main/taskprocessor.c
Modified: team/group/taskprocessors/main/taskprocessor.c
URL: http://svn.digium.com/view/asterisk/team/group/taskprocessors/main/taskprocessor.c?view=diff&rev=112561&r1=112560&r2=112561
==============================================================================
--- team/group/taskprocessors/main/taskprocessor.c (original)
+++ team/group/taskprocessors/main/taskprocessor.c Wed Apr 2 20:42:06 2008
@@ -337,6 +337,26 @@
return NULL;
}
+/*!
+ * \note Taskprocessors are uniquely identified by name
+ */
+static int tps_hash_cb(const void *obj, const int flags)
+{
+ const struct ast_taskprocessor *tps = obj;
+
+ return ast_str_hash(tps->name);
+}
+
+/*!
+ * \note Taskprocessors are uniquely identified by name
+ */
+static int tps_cmp_cb(void *obj, void *arg, int flags)
+{
+ struct ast_taskprocessor *lhs = obj, *rhs = arg;
+
+ return !strcasecmp(lhs->name, rhs->name) ? CMP_MATCH : 0;
+}
+
/*! \brief The default taskprocessor constructor creates an initialized taskprocessor structure
* \param poll_freq The polling frequency of the taskprocessor
* \return ast_taskprocessor structure on success, NULL on error
@@ -385,7 +405,6 @@
AST_LIST_LOCK(&taskprocessor_singletons);
AST_LIST_TRAVERSE(&taskprocessor_singletons, p, list) {
if (!strcasecmp(p->name, name)) {
- ast_debug(5, "taskprocessor_singleton \'%s\' already exists!.\n", p->name);
if ((create == TPS_REF_DEF) && (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);
AST_LIST_UNLOCK(&taskprocessor_singletons);
@@ -397,25 +416,22 @@
}
}
if (create == TPS_REF_IF_EXISTS) {
- /* we were told not to create a taskprocessor if it didn't exist, so lets take a holiday */
+ /* Reference a taskprocessor only if it already exists. It does not. */
AST_LIST_UNLOCK(&taskprocessor_singletons);
return NULL;
}
+ /* create a new taskprocessor */
if ((p = tps_default_constructor()) == NULL) {
ast_log(LOG_ERROR, "we can't create a taskprocessor_singleton because the default constructor failed.\n");
AST_LIST_UNLOCK(&taskprocessor_singletons);
return NULL;
}
ast_copy_string(p->name, name, sizeof(p->name));
- if (tps_taskprocessor_add(p) < 0) {
- ast_log(LOG_ERROR, "can't add taskprocessor_singleton \'%s\'\n", p->name);
- AST_LIST_UNLOCK(&taskprocessor_singletons);
- return ast_taskprocessor_unreference(p);
- }
p->poll_thread_run = 1;
- ast_debug(5, "creating taskprocessor \'%s\', taskprocessor count: %d\n", name, tps_taskprocessor_count());
- /* 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 */
+ /* reducing the ast_pthread_create() blocks below into a single block, with:
+ * 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. */
if (custom_func) {
p->poll_function = custom_func;
rc = ast_pthread_create(&p->poll_thread, NULL, custom_func, p);
@@ -425,6 +441,11 @@
}
if (rc < 0) {
ast_log(LOG_ERROR, "failed to create thread \'%s\'.\n", p->name);
+ AST_LIST_UNLOCK(&taskprocessor_singletons);
+ return ast_taskprocessor_unreference(p);
+ }
+ if (tps_taskprocessor_add(p) < 0) {
+ ast_log(LOG_ERROR, "can't add taskprocessor_singleton \'%s\'\n", p->name);
AST_LIST_UNLOCK(&taskprocessor_singletons);
return ast_taskprocessor_unreference(p);
}
More information about the asterisk-commits
mailing list