summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2016-01-20 14:18:44 -0600
committerGerrit Code Review <gerrit2@gerrit.digium.api>2016-01-20 14:18:45 -0600
commit09a6354f9e453c864426af0c7d79373f821983bf (patch)
tree4d69238ee4ae5590beda6e9c93c7fe9a0f7039c3
parenta2928b6093c5a32788cca0608913fe72bc4175c0 (diff)
parent0ab89182d9175cbae6944269d7e8f3e59bce6e1b (diff)
Merge topics 'increase_taskprocessor_timeout', 'fix_taskprocessor_unrefs' into 13
* changes: taskprocessor.c: Increase CLI "core ping taskprocessor" timeout. taskprocessor.c: Fix some taskprocessor unrefs.
-rw-r--r--main/taskprocessor.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/main/taskprocessor.c b/main/taskprocessor.c
index 05d646128..1ba0c8a2f 100644
--- a/main/taskprocessor.c
+++ b/main/taskprocessor.c
@@ -332,10 +332,11 @@ static void *tps_task_free(struct tps_task *task)
}
/* taskprocessor tab completion */
-static char *tps_taskprocessor_tab_complete(struct ast_taskprocessor *p, struct ast_cli_args *a)
+static char *tps_taskprocessor_tab_complete(struct ast_cli_args *a)
{
int tklen;
int wordnum = 0;
+ struct ast_taskprocessor *p;
char *name = NULL;
struct ao2_iterator i;
@@ -347,10 +348,10 @@ static char *tps_taskprocessor_tab_complete(struct ast_taskprocessor *p, struct
while ((p = ao2_iterator_next(&i))) {
if (!strncasecmp(a->word, p->name, tklen) && ++wordnum > a->n) {
name = ast_strdup(p->name);
- ao2_ref(p, -1);
+ ast_taskprocessor_unreference(p);
break;
}
- ao2_ref(p, -1);
+ ast_taskprocessor_unreference(p);
}
ao2_iterator_destroy(&i);
return name;
@@ -372,7 +373,7 @@ static char *cli_tps_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args
const char *name;
struct timeval when;
struct timespec ts;
- struct ast_taskprocessor *tps = NULL;
+ struct ast_taskprocessor *tps;
switch (cmd) {
case CLI_INIT:
@@ -382,7 +383,7 @@ static char *cli_tps_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args
" Displays the time required for a task to be processed\n";
return NULL;
case CLI_GENERATE:
- return tps_taskprocessor_tab_complete(tps, a);
+ return tps_taskprocessor_tab_complete(a);
}
if (a->argc != 4)
@@ -394,22 +395,32 @@ static char *cli_tps_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args
return CLI_SUCCESS;
}
ast_cli(a->fd, "\npinging %s ...", name);
- when = ast_tvadd((begin = ast_tvnow()), ast_samp2tv(1000, 1000));
+
+ /*
+ * Wait up to 5 seconds for a ping reply.
+ *
+ * On a very busy system it could take awhile to get a
+ * ping response from some taskprocessors.
+ */
+ begin = ast_tvnow();
+ when = ast_tvadd(begin, ast_samp2tv(5000, 1000));
ts.tv_sec = when.tv_sec;
ts.tv_nsec = when.tv_usec * 1000;
+
ast_mutex_lock(&cli_ping_cond_lock);
if (ast_taskprocessor_push(tps, tps_ping_handler, 0) < 0) {
ast_mutex_unlock(&cli_ping_cond_lock);
ast_cli(a->fd, "\nping failed: could not push task to %s\n\n", name);
- ao2_ref(tps, -1);
+ ast_taskprocessor_unreference(tps);
return CLI_FAILURE;
}
ast_cond_timedwait(&cli_ping_cond, &cli_ping_cond_lock, &ts);
ast_mutex_unlock(&cli_ping_cond_lock);
+
end = ast_tvnow();
delta = ast_tvsub(end, begin);
ast_cli(a->fd, "\n\t%24s ping time: %.1ld.%.6ld sec\n\n", name, (long)delta.tv_sec, (long int)delta.tv_usec);
- ao2_ref(tps, -1);
+ ast_taskprocessor_unreference(tps);
return CLI_SUCCESS;
}
@@ -663,6 +674,8 @@ static struct ast_taskprocessor *__allocate_taskprocessor(const char *name, stru
if (!(ao2_link(tps_singletons, p))) {
ast_log(LOG_ERROR, "Failed to add taskprocessor '%s' to container\n", p->name);
+ listener->tps = NULL;
+ ao2_ref(p, -1);
return NULL;
}