[asterisk-commits] dhubbard: branch group/taskprocessors r111601 - in /team/group/taskprocessors...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 27 23:51:35 CDT 2008


Author: dhubbard
Date: Thu Mar 27 23:50:16 2008
New Revision: 111601

URL: http://svn.digium.com/view/asterisk?view=rev&rev=111601
Log:
make taskprocessor ping CLI better

Modified:
    team/group/taskprocessors/include/asterisk/taskprocessor.h
    team/group/taskprocessors/main/asterisk.c
    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=111601&r1=111600&r2=111601
==============================================================================
--- team/group/taskprocessors/include/asterisk/taskprocessor.h (original)
+++ team/group/taskprocessors/include/asterisk/taskprocessor.h Thu Mar 27 23:50:16 2008
@@ -27,10 +27,6 @@
 struct a_task {
 	int (*execute)(struct a_task *t);
 	void *_datap;
-	size_t _datapsize;
-	void *_p_producer;
-	void *_p_consumer;
-	time_t _timestamp;
 	char _source[256];
 	AST_LIST_ENTRY(a_task) list;
 };
@@ -38,8 +34,6 @@
 struct taskprocessor_singleton_stats {
 	unsigned long _max_qsize;
 	unsigned long _tasks_processed_count;
-	unsigned long _queuetime;
-	unsigned long _queuetime_instances;
 };
 
 struct taskprocessor_singleton_info {
@@ -63,19 +57,16 @@
 	int (*queue_task)(struct ast_taskproducer *producer, struct a_task *task);
 }; 
 
-unsigned char _evtq_poll_thread_run;
+int ast_tps_init(void);
 
-int ast_taskprocessor_init(void);
 struct a_task *ast_task_alloc(int (*task_exe)(struct a_task *task), void *datap, char *src);
 int ast_task_free(struct a_task *task);
 
+struct taskprocessor_singleton_info *ast_taskprocessor_reference(const char *name, void *(*func)(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_depth(struct taskprocessor_singleton_info *tp);
 
-struct taskprocessor_singleton_info *ast_taskprocessor_reference(const char *name, void *(*func)(void*));
-int ast_taskprocessor_count(void);
-
 struct ast_taskproducer *ast_taskproducer_alloc(const char *name);
 #endif
 

Modified: team/group/taskprocessors/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/group/taskprocessors/main/asterisk.c?view=diff&rev=111601&r1=111600&r2=111601
==============================================================================
--- team/group/taskprocessors/main/asterisk.c (original)
+++ team/group/taskprocessors/main/asterisk.c Thu Mar 27 23:50:16 2008
@@ -2814,7 +2814,7 @@
 	ast_builtins_init();
 	ast_utils_init();
 	tdd_init();
-	ast_taskprocessor_init();
+	ast_tps_init();
 
 	if (getenv("HOME")) 
 		snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));

Modified: team/group/taskprocessors/main/taskprocessor.c
URL: http://svn.digium.com/view/asterisk/team/group/taskprocessors/main/taskprocessor.c?view=diff&rev=111601&r1=111600&r2=111601
==============================================================================
--- team/group/taskprocessors/main/taskprocessor.c (original)
+++ team/group/taskprocessors/main/taskprocessor.c Thu Mar 27 23:50:16 2008
@@ -24,6 +24,7 @@
  */
 
 #include <asterisk.h>
+#include <asterisk/time.h>
 #include <asterisk/astobj2.h>
 #include <asterisk/cli.h>
 #include <asterisk/taskprocessor.h>
@@ -34,10 +35,13 @@
 
 AST_LIST_HEAD_STATIC(_taskprocessor_singletons, taskprocessor_singleton_info);
 static int _taskprocessor_singletons_list_size = 0;
+static ast_cond_t _cli_ping_cond;
+static ast_mutex_t _cli_ping_cond_lock;
 
 static void *tps_default_processor_function(void *data);
 static struct taskprocessor_singleton_info *tps_default_constructor(void);
 static int tps_taskprocessor_add(struct taskprocessor_singleton_info *t);
+static int tps_taskprocessor_count(void);
 static void tps_taskprocessor_destroy(void *tps);
 static void tps_taskproducer_destroy(void *tp);
 static int tps_taskprocessor_ping_handler(struct a_task* e);
@@ -54,7 +58,7 @@
  * \param void
  * \return 0
  */
-int ast_taskprocessor_init(void)
+int ast_tps_init(void)
 {
 	ast_cli_register_multiple(taskprocessor_clis, sizeof(taskprocessor_clis)/sizeof(taskprocessor_clis[0]));
 	return 0;
@@ -97,7 +101,8 @@
  * \param a CLI arguments
  * \return NULL
  */
-static char *tps_taskprocessor_tab_complete(struct taskprocessor_singleton_info *p, struct ast_cli_args *a) {
+static char *tps_taskprocessor_tab_complete(struct taskprocessor_singleton_info *p, struct ast_cli_args *a) 
+{
 	int tklen;
 	int wordnum = 0;
 
@@ -116,6 +121,22 @@
 	return NULL;
 }
 
+/*! \brief CLI 'taskprocessor ping <blah>' operation handler
+ * \param task the ping task queued by the CLI operation
+ * \return 0 on success, -1 on error
+ */
+static int tps_taskprocessor_ping_handler(struct a_task *task)
+{
+	if (!task) {
+		ast_log(LOG_ERROR, "Huh?  There is no task?  This is terribly vexing!\n");
+		return -1;
+	}
+	ast_mutex_lock(&_cli_ping_cond_lock);
+	ast_cond_signal(&_cli_ping_cond);
+	ast_mutex_unlock(&_cli_ping_cond_lock);
+	return 0;
+}
+
 /*! \brief CLI 'taskprocessor ping' operation queues a ping task to the specified taskprocessor
  * \param e CLI entries
  * \param cmd 
@@ -124,9 +145,10 @@
  */
 static char *cli_taskprocessor_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
+	struct timeval begin, end, delta;
 	int found = 0;
 	struct a_task *t = NULL;
-	struct taskprocessor_singleton_info *p = NULL;
+	struct taskprocessor_singleton_info *tps = NULL;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -136,33 +158,44 @@
 			"	Displays the time required for a processor to deliver a task\n";
 		return NULL;
 	case CLI_GENERATE:
-		return tps_taskprocessor_tab_complete(p, a);
+		return tps_taskprocessor_tab_complete(tps, a);
 	}
 
 	if (a->argc != 3)
 		return CLI_SHOWUSAGE;
 
 	AST_LIST_LOCK(&_taskprocessor_singletons);
-	AST_LIST_TRAVERSE(&_taskprocessor_singletons, p, list) {
-		ast_mutex_lock(&p->_taskprocessor_lock);
-		if (!strcasecmp(p->_name, a->argv[2])) {
+	AST_LIST_TRAVERSE(&_taskprocessor_singletons, tps, list) {
+		ast_mutex_lock(&tps->_taskprocessor_lock);
+		if (!strcasecmp(tps->_name, a->argv[2])) {
 			found = 1;
 		}
-		ast_mutex_unlock(&p->_taskprocessor_lock);
+		ast_mutex_unlock(&tps->_taskprocessor_lock);
 		if (found) break;
 	}
 	AST_LIST_UNLOCK(&_taskprocessor_singletons);
 
-	if ((!found) || (!p)) {
-		ast_cli(a->fd, "\n%s failed: %s not found\n", e->command, a->argv[2]);
+	if (!found || !tps) {
+		ast_cli(a->fd, "\nping failed: %s not found\n\n", a->argv[2]);
 		return CLI_SUCCESS;
 	}
 
 	t = ast_task_alloc(tps_taskprocessor_ping_handler, 0, "cli_taskprocessor_ping");
-	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]);
+	begin = ast_tvnow();
+	if (ast_taskprocessor_push(tps, t) < 0) {
+		ast_cli(a->fd, "\nping failed: could not push task to %s\n\n", a->argv[2]);
 		ast_task_free(t);
 	}
+	ast_mutex_lock(&tps->_taskprocessor_lock);
+	ast_cond_signal(&tps->_poll_cond);
+	ast_mutex_unlock(&tps->_taskprocessor_lock);
+	
+	ast_mutex_lock(&_cli_ping_cond_lock);
+	ast_cond_wait(&_cli_ping_cond, &_cli_ping_cond_lock);
+	ast_mutex_unlock(&_cli_ping_cond_lock);
+	end = ast_tvnow();
+	delta = ast_tvsub(end, begin);
+	ast_cli(a->fd, "\n%24s ping time: %.1ld.%.6ld sec\n\n", a->argv[2], delta.tv_sec, (long int)delta.tv_usec);
 	return CLI_SUCCESS;	
 }
 
@@ -271,20 +304,6 @@
 	return NULL;
 }
 
-/*! \brief CLI 'taskprocessor ping <blah>' operation handler
- * \param task the ping task queued by the CLI operation
- * \return 0 on success, -1 on error
- */
-static int tps_taskprocessor_ping_handler(struct a_task *task)
-{
-	if (!task) {
-		ast_log(LOG_ERROR, "Huh?  There is no task?  This is totally unexpected!\n");
-		return -1;
-	}
-	ast_log(LOG_NOTICE, "[TASKPROCESSOR_CLI_PING] %s\n", task->_source);
-	return 0;
-}
-
 /*! \brief The default taskprocessor constructor creates an initialized taskprocessor structure
  * \param poll_freq The polling frequency of the taskprocessor
  * \return taskprocessor_singleton_info structure on success, NULL on error
@@ -353,7 +372,7 @@
 		return NULL;
 	}
 	p->_poll_thread_run = 1;
-	ast_debug(5, "creating taskprocessor \'%s\', taskprocessor count: %d\n", name, ast_taskprocessor_count());
+	ast_debug(5, "creating taskprocessor \'%s\', taskprocessor count: %d\n", name, tps_taskprocessor_count());
 	/* stay stopped if we are supposed to be stopped */
 	if (p->_poll_thread == AST_PTHREADT_STOP) {
 		ao2_ref(p, -1);
@@ -445,7 +464,7 @@
  * \param void
  * \return The number of taskprocessors in the taskprocessor container
  */
-int ast_taskprocessor_count(void)
+static int tps_taskprocessor_count(void)
 {
 	int size;
 	AST_LIST_LOCK(&_taskprocessor_singletons);




More information about the asterisk-commits mailing list