[asterisk-commits] dhubbard: branch dhubbard/named_processors r109765 - in /team/dhubbard/named_...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Mar 18 18:03:15 CDT 2008


Author: dhubbard
Date: Tue Mar 18 18:03:15 2008
New Revision: 109765

URL: http://svn.digium.com/view/asterisk?view=rev&rev=109765
Log:
taskproducer is gone and replaced with a macro

Modified:
    team/dhubbard/named_processors/apps/app_queue.c
    team/dhubbard/named_processors/include/asterisk/taskprocessor.h
    team/dhubbard/named_processors/main/pbx.c
    team/dhubbard/named_processors/main/taskprocessor.c
    team/dhubbard/named_processors/res/sandbox/simobject.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=109765&r1=109764&r2=109765
==============================================================================
--- team/dhubbard/named_processors/apps/app_queue.c (original)
+++ team/dhubbard/named_processors/apps/app_queue.c Tue Mar 18 18:03:15 2008
@@ -132,8 +132,7 @@
 	{ QUEUE_STRATEGY_WRANDOM, "wrandom"},
 };
 
-struct taskproducer *tpsp;
-struct taskprocessor_singleton_info *tpsi;
+struct taskprocessor_singleton_info *taskprocessor;
 
 #define DEFAULT_RETRY		5
 #define DEFAULT_TIMEOUT		15
@@ -792,8 +791,7 @@
 	}
 	sc->state = state;
 	strcpy(sc->dev, device);
-	t = ast_task_alloc(handle_statechange, sc, "app_queue-device_state_cb");
-	if (tpsp->queue_task(tpsp, t) < 0) {
+	if (AST_TASKPROCESSOR_QUEUE(taskprocessor, handle_statechange, sc) < 0) {
 		ast_log(LOG_WARNING, "queue_task failed!!\n");
 		ast_task_free(t);
 	}
@@ -6206,8 +6204,7 @@
 	clear_and_free_interfaces();
 
 	ao2_ref(queues, -1);
-	ao2_ref(tpsp, -1);
-	ao2_ref(tpsi, -1);
+	ao2_ref(taskprocessor, -1);
 	return res;
 }
 
@@ -6253,8 +6250,7 @@
 	res |= ast_custom_function_register(&queuewaitingcount_function);
 	res |= ast_custom_function_register(&queuememberpenalty_function);
 
-	tpsi = ast_taskprocessor_alloc("app_queue", 0);
-	tpsp = ast_taskproducer_alloc(tpsi);
+	taskprocessor = ast_taskprocessor_alloc("app_queue", 0);
 
 	if (!(device_state_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE, device_state_cb, NULL, AST_EVENT_IE_END)))
 		res = -1;

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=109765&r1=109764&r2=109765
==============================================================================
--- team/dhubbard/named_processors/include/asterisk/taskprocessor.h (original)
+++ team/dhubbard/named_processors/include/asterisk/taskprocessor.h Tue Mar 18 18:03:15 2008
@@ -54,16 +54,13 @@
 	struct taskprocessor_singleton_stats* _stats;
 	void *_private;
 	long _queue_size;
+	int (* queue_task)(struct taskprocessor_singleton_info *tp, struct a_task* task);
 	AST_LIST_HEAD(_queue, a_task) _queue;
 	AST_LIST_ENTRY(taskprocessor_singleton_info) list;
 };
 
-struct taskproducer {
-	struct taskprocessor_singleton_info* _taskprocessor;
-	unsigned long _tasks_produced;
-
-	int (* queue_task)(struct taskproducer* producer, struct a_task* task);
-}; 
+#define AST_TASKPROCESSOR_QUEUE(taskprocessor, function, data)	\
+	taskprocessor->queue_task(taskprocessor, ast_task_alloc(function, data, "blah"))
 
 unsigned char _evtq_poll_thread_run;
 
@@ -86,6 +83,5 @@
 int register_taskprocessor_clis(void);
 int unregister_taskprocessor_clis(void);
 
-struct taskproducer* ast_taskproducer_alloc(struct taskprocessor_singleton_info* processor);
 #endif
 

Modified: team/dhubbard/named_processors/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/main/pbx.c?view=diff&rev=109765&r1=109764&r2=109765
==============================================================================
--- team/dhubbard/named_processors/main/pbx.c (original)
+++ team/dhubbard/named_processors/main/pbx.c Tue Mar 18 18:03:15 2008
@@ -125,7 +125,6 @@
 struct ast_app;
 
 struct taskprocessor_singleton_info *taskprocessor;
-struct taskproducer *taskproducer;
 
 AST_THREADSTORAGE(switch_data);
 
@@ -7759,8 +7758,7 @@
 	if (!(sc = ast_calloc(1, sizeof(*sc) + strlen(device) + 1)))
 		return;
 	strcpy(sc->dev, device);
-	t = ast_task_alloc(handle_statechange, sc, "pbx-device_state_cb");
-	if (taskproducer->queue_task(taskproducer, t) < 0) {
+	if (AST_TASKPROCESSOR_QUEUE(taskprocessor, handle_statechange, sc) < 0) {
 		ast_log(LOG_WARNING, "queue_task failed!\n");
 		ast_task_free(t);
 	}
@@ -7790,7 +7788,6 @@
 	ast_manager_register2("ShowDialPlan", EVENT_FLAG_CONFIG | EVENT_FLAG_REPORTING, manager_show_dialplan, "List dialplan", mandescr_show_dialplan);
 
 	taskprocessor = ast_taskprocessor_alloc("pbx", 0);
-	taskproducer = ast_taskproducer_alloc(taskprocessor);
 
 	if (!(device_state_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE, device_state_cb, NULL,
 			AST_EVENT_IE_END))) {

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=109765&r1=109764&r2=109765
==============================================================================
--- team/dhubbard/named_processors/main/taskprocessor.c (original)
+++ team/dhubbard/named_processors/main/taskprocessor.c Tue Mar 18 18:03:15 2008
@@ -45,9 +45,9 @@
 static int _global_kill_taskpool = 0;
 AST_MUTEX_DEFINE_STATIC(_global_kill_taskpool_lock);
 
+static int default_queue_task(struct taskprocessor_singleton_info *tp, struct a_task* task);
 static int add_taskprocessor_singleton(struct taskprocessor_singleton_info* t);
 static void destroy_taskprocessor_singleton(void *tps);
-static void destroy_taskproducer(void *tp);
 static int taskprocessor_ping(struct a_task* e);
 
 static char *cli_taskprocessor_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
@@ -412,6 +412,7 @@
 		ao2_ref(tps, -1);
 		return NULL;
 	}
+	tps->queue_task = default_queue_task;
 	return tps;
 }
 	
@@ -621,43 +622,20 @@
 }
 
 /* provide a default implementation of a queue() command */
-static int default_queue_task(struct taskproducer* producer, struct a_task* task)
-{
-	if ((!producer) || (!task)) {
-		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);
+static int default_queue_task(struct taskprocessor_singleton_info *tp, struct a_task* task)
+{
+	if ((!tp) || (!task)) {
+		ast_log(LOG_ERROR, "a taskprocessor: 0x%ld and a task: 0x%ld are required for this operation.\n", (unsigned long)tp, (unsigned long)task);
 		return -1;
 	}
-	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>");
+	if (ast_taskprocessor_push(tp, task) < 0) {
+		ast_log(LOG_ERROR, "we failed to push task to taskprocessor \'%s\'.\n", tp->_name);
 		return -1;
 	}
-	producer->_tasks_produced++;
-	ast_mutex_lock(&producer->_taskprocessor->_taskprocessor_lock);
-	ast_cond_signal(&producer->_taskprocessor->_poll_cond);
-	ast_mutex_unlock(&producer->_taskprocessor->_taskprocessor_lock);
-	return 0;
-}
-
-/* create and initialize a task producer */
-struct taskproducer* ast_taskproducer_alloc(struct taskprocessor_singleton_info* processor)
-{
-	struct taskproducer* p;
-	p = ao2_alloc(sizeof(*p), destroy_taskproducer);
-	if (!p) {
-		ast_log(LOG_ERROR, "cannot allocate memory for a taskproducer structure.\n");
-		return NULL;
-	}
-	p->_taskprocessor = processor;
-	ao2_ref(processor, 1);
-	p->queue_task = default_queue_task;
-	return p;
-}
-
-static void destroy_taskproducer(void *tp)
-{
-	struct taskproducer *p;
-	p = (struct taskproducer *)tp;
-	ast_log(LOG_DEBUG, "destroying taskproducer\n");
-	ao2_ref(p->_taskprocessor, -1);
-}
-
+	ast_mutex_lock(&tp->_taskprocessor_lock);
+	ast_cond_signal(&tp->_poll_cond);
+	ast_mutex_unlock(&tp->_taskprocessor_lock);
+	return 0;
+}
+
+

Modified: team/dhubbard/named_processors/res/sandbox/simobject.c
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/res/sandbox/simobject.c?view=diff&rev=109765&r1=109764&r2=109765
==============================================================================
--- team/dhubbard/named_processors/res/sandbox/simobject.c (original)
+++ team/dhubbard/named_processors/res/sandbox/simobject.c Tue Mar 18 18:03:15 2008
@@ -23,7 +23,6 @@
 #include "include/simobject.h"
 
 static int start_simobject(struct simobject* s);
-static int start_simproducer(struct simobject* s);
 static int simobject_taskhandler(struct a_task* t);
 static void* _simproducer_thread_function(void* data);
 static void destroy_simobject(void *sim);
@@ -44,7 +43,6 @@
 		return NULL;
 	}
 	snprintf(s->_name, sizeof(s->_name), "%s", name);
-	s->_producer = ast_taskproducer_alloc(t);
 	s->_consumer = ast_taskconsumer_alloc(t);
 	s->start = start_simobject;
 	return s;
@@ -68,7 +66,6 @@
 	}
 	snprintf(s->_name, sizeof(s->_name), "%s", name);
 	snprintf(tpg, sizeof(tpg), "%s-generator", s->_name);
-	s->_producer = ast_taskproducer_alloc(t);
 	s->_consumer = ast_taskconsumer_alloc(t);
 	s->_taskgenerator = ast_taskprocessor_alloc(tpg, _simproducer_thread_function);
 	if (!s->_taskgenerator) {
@@ -77,7 +74,6 @@
 		return NULL;
 	}
 	s->_taskgenerator->_private = s;
-	s->start = start_simproducer;
 	return s;
 
 }
@@ -115,9 +111,6 @@
 		pthread_join(s->_taskgenerator->_poll_thread, NULL);
 		s->_taskgenerator->_poll_thread = AST_PTHREADT_NULL;
 	}
-	if (s->_producer) {
-		ao2_ref(s->_producer, -1);
-	}
 	if (s->_consumer) {
 		ao2_ref(s->_consumer, -1);
 	}
@@ -128,8 +121,8 @@
 
 int start_simobject(struct simobject* s)
 {
+#if 0
 	struct a_task* t = NULL;
-	
 	if (s && s->_producer) {
 		t = ast_task_alloc(simobject_taskhandler, 0, "start_simobject");
 		if (!t) {
@@ -144,13 +137,14 @@
 			return -1;
 		}
 	}
+#endif
 	return 0;
 }
 
-int start_simproducer(struct simobject* s)
-{
+//int start_simproducer(struct simobject* s)
+//{
+#if 0	
 	struct a_task* t = NULL;
-	
 	if (s && s->_producer) {
 		t = ast_task_alloc(simobject_taskhandler, 0, "start_simproducer");
 		if (!t) {
@@ -164,8 +158,9 @@
 			return -1;
 		}
 	}
-	return 0;
-}
+#endif
+//	return 0;
+//}
 
 static int simobject_taskhandler(struct a_task* e)
 {
@@ -227,14 +222,15 @@
 			ast_log(LOG_ERROR, "ERROR: task pool failed to supply a task\n");
 			break;
 		}
-		t->_p_producer = s->_producer;
 		t->_p_consumer = s->_consumer;
+#if 0
 		if (s->_producer && s->_producer->queue_task && (s->_producer->queue_task(s->_producer, t))) {
 			ast_log(LOG_WARNING, "simobject \'%s\' failed to queue task (producer: 0x%ld, generator: 0x%ld)!  Releasing task to task pool\n"
 				, s->_name, (unsigned long)s->_producer, (unsigned long)s->_taskgenerator);
 			ast_task_free(t);
 			break;
 		}
+#endif
 		ast_mutex_lock(&i->_taskprocessor_lock);
 		ast_cond_timedwait(&i->_poll_cond, &i->_taskprocessor_lock, &ts);
 		ast_mutex_unlock(&i->_taskprocessor_lock);




More information about the asterisk-commits mailing list