[asterisk-commits] dhubbard: branch dhubbard/named_processors r108892 - in /team/dhubbard/named_...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Mar 15 00:45:14 CDT 2008
Author: dhubbard
Date: Sat Mar 15 00:45:12 2008
New Revision: 108892
URL: http://svn.digium.com/view/asterisk?view=rev&rev=108892
Log:
changes to function names and some general cleanup
Modified:
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/include/asterisk/taskprocessor.h
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/include/asterisk/taskprocessor.h?view=diff&rev=108892&r1=108891&r2=108892
==============================================================================
--- team/dhubbard/named_processors/include/asterisk/taskprocessor.h (original)
+++ team/dhubbard/named_processors/include/asterisk/taskprocessor.h Sat Mar 15 00:45:12 2008
@@ -67,16 +67,13 @@
unsigned char _evtq_poll_thread_run;
-/*
- * get an available a_task structure from the pool of available
- * structures. If no structures are available, allocate one
- */
struct a_task* ast_task_alloc(int (*task_exe)(struct a_task *task), void* datap, char* src);
-int task_pool_size(void);
-/*
- * release a_task structure back to the pool
- */
int ast_task_free(struct a_task* task);
+int ast_task_poolsize(void);
+
+int ast_taskprocessor_push(struct taskprocessor_singleton_info* tp, struct a_task* t);
+struct a_task* ast_taskprocessor_pop(struct taskprocessor_singleton_info* tp);
+int ast_taskprocessor_size(struct taskprocessor_singleton_info* tp);
int stop_taskpool(void);
int destroy_task_pool(void);
@@ -84,14 +81,9 @@
int noop_task_execute(struct a_task* t);
int create_taskprocessor_singleton(const char* name, void* (*func)(void*));
-int start_taskprocessor_singleton(const char* name);
int size_of_taskprocessor_singleton_list(void);
struct taskprocessor_singleton_info* get_taskprocessor_singleton(const char* name);
int exists_taskprocessor_singleton(char *name);
-
-int push_task_to_taskprocessor_singleton(struct taskprocessor_singleton_info* tp, struct a_task* t);
-struct a_task* pop_task_from_taskprocessor_singleton(struct taskprocessor_singleton_info* tp);
-int size_of_taskprocessor_singleton_queue(struct taskprocessor_singleton_info* tp);
int register_taskprocessor_clis(void);
int unregister_taskprocessor_clis(void);
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=108892&r1=108891&r2=108892
==============================================================================
--- team/dhubbard/named_processors/main/taskprocessor.c (original)
+++ team/dhubbard/named_processors/main/taskprocessor.c Sat Mar 15 00:45:12 2008
@@ -39,7 +39,7 @@
AST_LIST_HEAD_STATIC(_taskprocessor_singletons, taskprocessor_singleton_info);
static int _taskprocessor_singletons_list_size = 0;
-static long _task_pool_size = 0;
+static long _task_poolsize = 0;
AST_LIST_HEAD_STATIC(_task_pool, a_task);
static int _global_kill_taskpool = 0;
@@ -79,7 +79,7 @@
AST_LIST_UNLOCK(&_task_pool);
usleep(1);
if (lock_failures > 10) {
- ast_log(LOG_ERROR, "\n\tcannot lock task pool for \'%s\'.\n", src);
+ ast_log(LOG_ERROR, "cannot lock task pool for \'%s\'.\n", src);
return NULL;
}
AST_LIST_LOCK(&_task_pool);
@@ -88,7 +88,7 @@
if (_global_kill_taskpool) {
ast_mutex_unlock(&_global_kill_taskpool_lock);
AST_LIST_UNLOCK(&_task_pool);
- ast_log(LOG_NOTICE, "task pool is no longer available to requestors.\n");
+ ast_log(LOG_DEBUG, "task pool is no longer available to requestors.\n");
return NULL;
}
if (AST_LIST_EMPTY(&_task_pool)) {
@@ -107,7 +107,7 @@
return t;
}
t = AST_LIST_REMOVE_HEAD(&_task_pool, list);
- _task_pool_size -= 1;
+ _task_poolsize -= 1;
ast_mutex_unlock(&_global_kill_taskpool_lock);
AST_LIST_UNLOCK(&_task_pool);
if (t) {
@@ -146,7 +146,7 @@
return 0;
}
AST_LIST_INSERT_TAIL(&_task_pool, t, list);
- _task_pool_size += 1;
+ _task_poolsize += 1;
ast_mutex_unlock(&_global_kill_taskpool_lock);
AST_LIST_UNLOCK(&_task_pool);
return 0;
@@ -163,11 +163,11 @@
return 0;
}
-int task_pool_size()
+int ast_task_poolsize()
{
int size = 0;
AST_LIST_LOCK(&_task_pool);
- size = _task_pool_size;
+ size = _task_poolsize;
AST_LIST_UNLOCK(&_task_pool);
return size;
}
@@ -186,7 +186,7 @@
ast_free(t);
t = NULL;
}
- _task_pool_size -= 1;
+ _task_poolsize -= 1;
}
AST_LIST_UNLOCK(&_task_pool);
return 0;
@@ -234,7 +234,7 @@
ast_cli(a->fd, "\n%s failed: could not retrieve task from pool\n", e->command);
return RESULT_SUCCESS;
}
- if (push_task_to_taskprocessor_singleton(p, t) < 0) {
+ if (ast_taskprocessor_push(p, t) < 0) {
ast_cli(a->fd, "\n%s failed: could not push task to %s\n", e->command, a->argv[2]);
ast_task_free(t);
}
@@ -275,7 +275,7 @@
ast_cli(a->fd, "\n%20s: processed: %10ld, qsize: %ld (max: %ld)", name, processed, qsize, maxqsize);
}
AST_LIST_UNLOCK(&_taskprocessor_singletons);
- taskpool = task_pool_size();
+ taskpool = ast_task_poolsize();
ast_cli(a->fd, "\n%20s: %ld\n\n", "task pool size", taskpool);
return RESULT_SUCCESS;
@@ -285,8 +285,8 @@
{
struct taskprocessor_singleton_info* i;
struct a_task* t;
- long size;
struct timeval tv;
+ int size;
int killflag = 0;
struct timespec ts = { 0, };
@@ -297,21 +297,19 @@
}
while ((!killflag) && (i->_poll_thread_run)) {
- if ((size = size_of_taskprocessor_singleton_queue(i)) > 0) {
+ if ((size = ast_taskprocessor_size(i)) > 0) {
/* stuff is in the queue */
- t = pop_task_from_taskprocessor_singleton(i);
+ t = ast_taskprocessor_pop(i);
if (!t) {
- ast_log(LOG_ERROR, "Huh?? size of queue is not zero(%ld), but the queue popped a NULL!\n", size);
+ ast_log(LOG_ERROR, "Wtf?? %d tasks in the queue, but we're popping blanks!\n", size);
continue;
}
if (!t->execute) {
- ast_log(LOG_ERROR, "task is missing its execute callback.\n");
+ ast_log(LOG_WARNING, "A task from '\%s\' has no function to execute\n", t->_source);
ast_task_free(t);
continue;
}
- if (t->execute(t) < 0) {
- ast_log(LOG_ERROR, "execute() returned failure.\n");
- }
+ t->execute(t);
ast_mutex_lock(&i->_taskprocessor_lock);
if (i->_stats) {
i->_stats->_tasks_processed_count++;
@@ -322,7 +320,7 @@
ast_mutex_unlock(&i->_taskprocessor_lock);
ast_task_free(t);
t = NULL;
-
+
ast_mutex_lock(&_global_killflag_lock);
killflag = _global_killflag;
ast_mutex_unlock(&_global_killflag_lock);
@@ -340,9 +338,9 @@
killflag = _global_killflag;
ast_mutex_unlock(&_global_killflag_lock);
}
- while (size_of_taskprocessor_singleton_queue(i)) {
+ while (ast_taskprocessor_size(i)) {
/* stuff is in the queue */
- t = pop_task_from_taskprocessor_singleton(i);
+ t = ast_taskprocessor_pop(i);
if (t) {
ast_task_free(t);
t = NULL;
@@ -452,12 +450,6 @@
return 0;
}
-int start_taskprocessor_singleton(const char* name)
-{
- ast_log(LOG_NOTICE, "stub function\n");
- return -1;
-}
-
static void destroy_taskprocessor_singleton(void *tps)
{
struct taskprocessor_singleton_info *t = (struct taskprocessor_singleton_info *)tps;
@@ -565,11 +557,11 @@
return size;
}
-int push_task_to_taskprocessor_singleton(struct taskprocessor_singleton_info* tp, struct a_task* t)
+int ast_taskprocessor_push(struct taskprocessor_singleton_info* tp, struct a_task* t)
{
int lock_failures = 0;
- if ((!tp) || (!t)) {
+ if (!tp || !t) {
ast_log(LOG_ERROR, "a taskprocessor (0x%ld) and a task (0x%ld) are required and missing.\n", (long)tp, (long)t);
return -1;
}
@@ -592,50 +584,50 @@
return 0;
}
-struct a_task* pop_task_from_taskprocessor_singleton(struct taskprocessor_singleton_info* tp)
-{
- struct a_task* t = NULL;
+struct a_task* ast_taskprocessor_pop(struct taskprocessor_singleton_info* tps)
+{
+ struct a_task* t;
int lock_failures = 0;
- AST_LIST_LOCK(&tp->_queue);
- while (ast_mutex_trylock(&tp->_taskprocessor_lock)) {
+ AST_LIST_LOCK(&tps->_queue);
+ while (ast_mutex_trylock(&tps->_taskprocessor_lock)) {
lock_failures++;
- AST_LIST_UNLOCK(&tp->_queue);
+ AST_LIST_UNLOCK(&tps->_queue);
usleep(1);
if (lock_failures > 10) {
- ast_log(LOG_ERROR, "cannot lock taskprocessor.\n");
+ ast_log(LOG_ERROR, "cannot lock taskprocessor \'%s\'.\n", tps->_name);
return t;
}
- AST_LIST_LOCK(&tp->_queue);
- }
- if (!AST_LIST_EMPTY(&tp->_queue)) {
- t = AST_LIST_REMOVE_HEAD(&tp->_queue, list);
- tp->_queue_size-=1;
- }
- ast_mutex_unlock(&tp->_taskprocessor_lock);
- AST_LIST_UNLOCK(&tp->_queue);
+ AST_LIST_LOCK(&tps->_queue);
+ }
+ if (!AST_LIST_EMPTY(&tps->_queue)) {
+ t = AST_LIST_REMOVE_HEAD(&tps->_queue, list);
+ tps->_queue_size-=1;
+ }
+ ast_mutex_unlock(&tps->_taskprocessor_lock);
+ AST_LIST_UNLOCK(&tps->_queue);
return t;
}
-int size_of_taskprocessor_singleton_queue(struct taskprocessor_singleton_info* tp)
+int ast_taskprocessor_size(struct taskprocessor_singleton_info* tps)
{
int size = -1;
int lock_failures = 0;
- AST_LIST_LOCK(&tp->_queue);
- while (ast_mutex_trylock(&tp->_taskprocessor_lock)) {
+ AST_LIST_LOCK(&tps->_queue);
+ while (ast_mutex_trylock(&tps->_taskprocessor_lock)) {
lock_failures++;
- AST_LIST_UNLOCK(&tp->_queue);
+ AST_LIST_UNLOCK(&tps->_queue);
usleep(1);
if (lock_failures > 10) {
- ast_log(LOG_ERROR, "cannot lock taskprocessor.\n");
+ ast_log(LOG_ERROR, "cannot lock taskprocessor \'%s\'.\n", tps->_name);
return size;
}
- AST_LIST_LOCK(&tp->_queue);
- }
- size = tp->_queue_size;
- ast_mutex_unlock(&tp->_taskprocessor_lock);
- AST_LIST_UNLOCK(&tp->_queue);
+ AST_LIST_LOCK(&tps->_queue);
+ }
+ size = tps->_queue_size;
+ ast_mutex_unlock(&tps->_taskprocessor_lock);
+ AST_LIST_UNLOCK(&tps->_queue);
return size;
}
@@ -646,7 +638,7 @@
ast_log(LOG_ERROR, "a taskproducer: 0x%ld and a task: 0x%ld are required for this operation.\n", (unsigned long)producer, (unsigned long)task);
return -1;
}
- if (push_task_to_taskprocessor_singleton(producer->_taskprocessor, task) < 0) {
+ if (ast_taskprocessor_push(producer->_taskprocessor, task) < 0) {
ast_log(LOG_ERROR, "we failed to push task to taskprocessor \'%s\'.\n", (producer->_taskprocessor)?producer->_taskprocessor->_name:"<null>");
return -1;
}
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=108892&r1=108891&r2=108892
==============================================================================
--- team/dhubbard/named_processors/res/res_testobserver.c (original)
+++ team/dhubbard/named_processors/res/res_testobserver.c Sat Mar 15 00:45:12 2008
@@ -155,9 +155,9 @@
while ((!killflag) && (i->_poll_thread_run)) {
loop_count++;
- if ((size = size_of_taskprocessor_singleton_queue(i)) > 0) {
+ if ((size = ast_taskprocessor_size(i)) > 0) {
/* stuff is in the queue */
- t = pop_task_from_taskprocessor_singleton(i);
+ t = ast_taskprocessor_pop(i);
if (!t) {
ast_log(LOG_ERROR, "Huh?? size of queue is not zero(%ld), but the queue popped a NULL!\n", qsize);
continue;
@@ -201,9 +201,9 @@
ast_mutex_unlock(&_global_killflag_lock);
}
ast_log(LOG_NOTICE, "purging \'%s\' after %ld loops.\n", i->_name, loop_count);
- while (size_of_taskprocessor_singleton_queue(i)) {
+ while (ast_taskprocessor_size(i)) {
/* stuff is in the queue */
- t = pop_task_from_taskprocessor_singleton(i);
+ t = ast_taskprocessor_pop(i);
if (t) {
ast_task_free(t);
t = NULL;
@@ -263,7 +263,7 @@
}
ast_log(LOG_NOTICE, "started %d processors, task pool size: %d\n"
- , size_of_taskprocessor_singleton_list(), task_pool_size());
+ , size_of_taskprocessor_singleton_list(), ast_task_poolsize());
if (ast_register_application(app, app_exec, synopsis, descrip))
return AST_MODULE_LOAD_DECLINE;
More information about the asterisk-commits
mailing list