[svn-commits] dhubbard: branch dhubbard/named_processors r108675 - in /team/dhubbard/named_...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Thu Mar 13 23:26:58 CDT 2008
Author: dhubbard
Date: Thu Mar 13 23:26:56 2008
New Revision: 108675
URL: http://svn.digium.com/view/asterisk?view=rev&rev=108675
Log:
use astobj2
Modified:
team/dhubbard/named_processors/apps/app_queue.c
team/dhubbard/named_processors/include/asterisk/taskprocessor.h
team/dhubbard/named_processors/main/taskprocessor.c
team/dhubbard/named_processors/res/res_testobserver.c
Modified: team/dhubbard/named_processors/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/apps/app_queue.c?view=diff&rev=108675&r1=108674&r2=108675
==============================================================================
--- team/dhubbard/named_processors/apps/app_queue.c (original)
+++ team/dhubbard/named_processors/apps/app_queue.c Thu Mar 13 23:26:56 2008
@@ -6221,7 +6221,7 @@
clear_and_free_interfaces();
ao2_ref(queues, -1);
-
+ ao2_ref(tpsi, -1);
return res;
}
Modified: team/dhubbard/named_processors/include/asterisk/taskprocessor.h
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/include/asterisk/taskprocessor.h?view=diff&rev=108675&r1=108674&r2=108675
==============================================================================
--- team/dhubbard/named_processors/include/asterisk/taskprocessor.h (original)
+++ team/dhubbard/named_processors/include/asterisk/taskprocessor.h Thu Mar 13 23:26:56 2008
@@ -58,8 +58,6 @@
int create_taskprocessor_singleton(const char* name, void* (*func)(void*));
int start_taskprocessor_singleton(const char* name);
-int stop_taskprocessor_singleton(const char* name);
-int destroy_taskprocessor_singleton(struct taskprocessor_singleton_info* t);
int size_of_taskprocessor_singleton_list(void);
struct taskprocessor_singleton_info* get_taskprocessor_singleton(const char* name);
int exists_taskprocessor_singleton(char *name);
Modified: team/dhubbard/named_processors/main/taskprocessor.c
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/main/taskprocessor.c?view=diff&rev=108675&r1=108674&r2=108675
==============================================================================
--- team/dhubbard/named_processors/main/taskprocessor.c (original)
+++ team/dhubbard/named_processors/main/taskprocessor.c Thu Mar 13 23:26:56 2008
@@ -19,9 +19,10 @@
* Maintain a container of taskprocessor threads that are uniquely named
*/
#include <asterisk.h>
+#include <asterisk/astobj2.h>
+#include <asterisk/cli.h>
+#include <asterisk/task.h>
#include <asterisk/taskprocessor.h>
-#include <asterisk/task.h>
-#include <asterisk/cli.h>
#include <signal.h>
#include <sys/time.h>
@@ -40,6 +41,7 @@
static int _taskprocessor_singletons_list_size = 0;
static int add_taskprocessor_singleton(struct taskprocessor_singleton_info* t);
+static void destroy_taskprocessor_singleton(void *tps);
static int remove_taskprocessor_singleton(const char* name);
static int taskprocessor_ping(struct a_task* e);
@@ -239,28 +241,28 @@
}
-static struct taskprocessor_singleton_info* default_taskprocessor_constructor(int poll_freq)
-{
- struct taskprocessor_singleton_info* t;
- t = ast_calloc(1, sizeof(*t));
- if (!t) {
+static struct taskprocessor_singleton_info* construct_default_taskprocessor(int poll_freq)
+{
+ struct taskprocessor_singleton_info* tps;
+ tps = ao2_alloc(sizeof(*tps), destroy_taskprocessor_singleton);
+ if (!tps) {
ast_log(LOG_ERROR, "cannot allocate memory for a taskprocessor_singleton_info structure.\n");
return NULL;
}
- t->_id = (unsigned long)t;
+ tps->_id = (unsigned long)tps;
if (poll_freq < 1)
- t->_poll_freq = DEFAULT_POLL_FREQUENCY;
+ tps->_poll_freq = DEFAULT_POLL_FREQUENCY;
else
- t->_poll_freq = poll_freq;
- ast_cond_init(&t->_poll_cond, NULL);
- t->_poll_thread = AST_PTHREADT_NULL;
- t->_stats = ast_calloc(1, sizeof(*t->_stats));
- if (!t->_stats) {
+ tps->_poll_freq = poll_freq;
+ ast_cond_init(&tps->_poll_cond, NULL);
+ tps->_poll_thread = AST_PTHREADT_NULL;
+ tps->_stats = ast_calloc(1, sizeof(*tps->_stats));
+ if (!tps->_stats) {
ast_log(LOG_ERROR, "cannot allocate memory for a taskprocessor_singleton_stats structure.\n");
- ast_free(t);
- return NULL;
- }
- return t;
+ ast_free(tps);
+ return NULL;
+ }
+ return tps;
}
int create_taskprocessor_singleton(const char* name, void* (*func)(void*))
@@ -275,7 +277,7 @@
}
ast_mutex_unlock(&_global_clireg_lock);
- p = default_taskprocessor_constructor(1);
+ p = construct_default_taskprocessor(1);
if (!p) {
ast_log(LOG_ERROR, "we can't create a taskprocessor_singleton because the default constructor failed.\n");
return -1;
@@ -322,36 +324,20 @@
return -1;
}
-int stop_taskprocessor_singleton(const char* name)
-{
- struct taskprocessor_singleton_info* p;
- p = get_taskprocessor_singleton(name);
- if (!p) {
- ast_log(LOG_ERROR, "no taskprocessor named \'%s\' to stop.\n", name);
- return -1;
- }
- p->_poll_thread_run = 0;
-
- ast_mutex_lock(&p->_taskprocessor_lock);
- ast_cond_signal(&p->_poll_cond);
- ast_mutex_unlock(&p->_taskprocessor_lock);
-
- pthread_join(p->_poll_thread, NULL);
- p->_poll_thread = AST_PTHREADT_NULL;
- ast_log(LOG_DEBUG, "taskprocessor \'%s\' stopped.\n", name);
- return destroy_taskprocessor_singleton(p);
-}
-
-int destroy_taskprocessor_singleton(struct taskprocessor_singleton_info* t)
-{
+static void destroy_taskprocessor_singleton(void *tps)
+{
+ struct taskprocessor_singleton_info *t = (struct taskprocessor_singleton_info *)tps;
if (!t) {
ast_log(LOG_ERROR, "can't destruct a NULL taskprocessor_singleton.\n");
- return -1;
- }
- if (t->_poll_thread_run) {
- ast_log(LOG_ERROR, "stop the taskprocessor before trying to destruct it.\n");
- return -1;
- }
+ return;
+ }
+ t->_poll_thread_run = 0;
+ ast_mutex_lock(&t->_taskprocessor_lock);
+ ast_cond_signal(&t->_poll_cond);
+ ast_mutex_unlock(&t->_taskprocessor_lock);
+ pthread_join(t->_poll_thread, NULL);
+ t->_poll_thread = AST_PTHREADT_NULL;
+
if (remove_taskprocessor_singleton(t->_name) < 0) {
ast_log(LOG_WARNING, "cannot remove taskprocessor_singleton \'%s\'.\n", t->_name);
}
@@ -359,9 +345,7 @@
ast_free(t->_stats);
t->_stats = NULL;
}
- ast_free(t);
- t = NULL;
- return 0;
+ return;
}
int exists_taskprocessor_singleton(char *name)
Modified: team/dhubbard/named_processors/res/res_testobserver.c
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/res/res_testobserver.c?view=diff&rev=108675&r1=108674&r2=108675
==============================================================================
--- team/dhubbard/named_processors/res/res_testobserver.c (original)
+++ team/dhubbard/named_processors/res/res_testobserver.c Thu Mar 13 23:26:56 2008
@@ -230,10 +230,7 @@
for (count=0; count < MAX_TEST_PROCESSORS; count++) {
snprintf(tbuf, sizeof(tbuf), "sillyprocessor-%d", count);
if (exists_taskprocessor_singleton(tbuf)) {
- if (stop_taskprocessor_singleton(tbuf) < 0) {
- ast_log(LOG_ERROR, "can't stop \'%s\' taskprocessor singleton\n", tbuf);
- return -1;
- }
+ ao2_ref(get_taskprocessor_singleton(tbuf), -1);
}
}
ast_log(LOG_NOTICE, "-- testobserver -- unload complete.\n");
More information about the svn-commits
mailing list