Skip to content
Snippets Groups Projects
Unverified Commit dc54dc04 authored by Corey Farrell's avatar Corey Farrell
Browse files

taskprocessor: Do not use separate allocation for stats or name.

Merge storage for the stats object and name string into the main
allocation for struct ast_taskprocessor.

Change-Id: I74fe9a7f357f0e6d63152f163cf5eef6428218e1
parent 6aea312a
Branches
Tags
No related merge requests found
...@@ -69,10 +69,8 @@ struct tps_taskprocessor_stats { ...@@ -69,10 +69,8 @@ struct tps_taskprocessor_stats {
/*! \brief A ast_taskprocessor structure is a singleton by name */ /*! \brief A ast_taskprocessor structure is a singleton by name */
struct ast_taskprocessor { struct ast_taskprocessor {
/*! \brief Friendly name of the taskprocessor */
const char *name;
/*! \brief Taskprocessor statistics */ /*! \brief Taskprocessor statistics */
struct tps_taskprocessor_stats *stats; struct tps_taskprocessor_stats stats;
void *local_data; void *local_data;
/*! \brief Taskprocessor current queue size */ /*! \brief Taskprocessor current queue size */
long tps_queue_size; long tps_queue_size;
...@@ -93,6 +91,8 @@ struct ast_taskprocessor { ...@@ -93,6 +91,8 @@ struct ast_taskprocessor {
unsigned int high_water_alert:1; unsigned int high_water_alert:1;
/*! Indicates if the taskprocessor is currently suspended */ /*! Indicates if the taskprocessor is currently suspended */
unsigned int suspended:1; unsigned int suspended:1;
/*! \brief Friendly name of the taskprocessor */
char name[0];
}; };
/*! /*!
...@@ -517,13 +517,8 @@ static char *cli_tps_report(struct ast_cli_entry *e, int cmd, struct ast_cli_arg ...@@ -517,13 +517,8 @@ static char *cli_tps_report(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
while ((tps = ao2_iterator_next(&iter))) { while ((tps = ao2_iterator_next(&iter))) {
ast_copy_string(name, tps->name, sizeof(name)); ast_copy_string(name, tps->name, sizeof(name));
qsize = tps->tps_queue_size; qsize = tps->tps_queue_size;
if (tps->stats) { maxqsize = tps->stats.max_qsize;
maxqsize = tps->stats->max_qsize; processed = tps->stats._tasks_processed_count;
processed = tps->stats->_tasks_processed_count;
} else {
maxqsize = 0;
processed = 0;
}
ast_cli(a->fd, FMT_FIELDS, name, processed, qsize, maxqsize, ast_cli(a->fd, FMT_FIELDS, name, processed, qsize, maxqsize,
tps->tps_queue_low, tps->tps_queue_high); tps->tps_queue_low, tps->tps_queue_high);
ast_taskprocessor_unreference(tps); ast_taskprocessor_unreference(tps);
...@@ -647,10 +642,6 @@ static void tps_taskprocessor_dtor(void *tps) ...@@ -647,10 +642,6 @@ static void tps_taskprocessor_dtor(void *tps)
tps_alert_add(t, -1); tps_alert_add(t, -1);
} }
ast_free(t->stats);
t->stats = NULL;
ast_free((char *) t->name);
t->name = NULL;
ao2_cleanup(t->listener); ao2_cleanup(t->listener);
t->listener = NULL; t->listener = NULL;
} }
...@@ -746,7 +737,7 @@ static struct ast_taskprocessor *__allocate_taskprocessor(const char *name, stru ...@@ -746,7 +737,7 @@ static struct ast_taskprocessor *__allocate_taskprocessor(const char *name, stru
{ {
struct ast_taskprocessor *p; struct ast_taskprocessor *p;
p = ao2_alloc(sizeof(*p), tps_taskprocessor_dtor); p = ao2_alloc(sizeof(*p) + strlen(name) + 1, tps_taskprocessor_dtor);
if (!p) { if (!p) {
ast_log(LOG_WARNING, "failed to create taskprocessor '%s'\n", name); ast_log(LOG_WARNING, "failed to create taskprocessor '%s'\n", name);
return NULL; return NULL;
...@@ -756,12 +747,7 @@ static struct ast_taskprocessor *__allocate_taskprocessor(const char *name, stru ...@@ -756,12 +747,7 @@ static struct ast_taskprocessor *__allocate_taskprocessor(const char *name, stru
p->tps_queue_low = (AST_TASKPROCESSOR_HIGH_WATER_LEVEL * 9) / 10; p->tps_queue_low = (AST_TASKPROCESSOR_HIGH_WATER_LEVEL * 9) / 10;
p->tps_queue_high = AST_TASKPROCESSOR_HIGH_WATER_LEVEL; p->tps_queue_high = AST_TASKPROCESSOR_HIGH_WATER_LEVEL;
p->stats = ast_calloc(1, sizeof(*p->stats)); strcpy(p->name, name); /*SAFE*/
p->name = ast_strdup(name);
if (!p->stats || !p->name) {
ao2_ref(p, -1);
return NULL;
}
ao2_ref(listener, +1); ao2_ref(listener, +1);
p->listener = listener; p->listener = listener;
...@@ -987,13 +973,11 @@ int ast_taskprocessor_execute(struct ast_taskprocessor *tps) ...@@ -987,13 +973,11 @@ int ast_taskprocessor_execute(struct ast_taskprocessor *tps)
size = ast_taskprocessor_size(tps); size = ast_taskprocessor_size(tps);
/* Update the stats */ /* Update the stats */
if (tps->stats) { ++tps->stats._tasks_processed_count;
++tps->stats->_tasks_processed_count;
/* Include the task we just executed as part of the queue size. */ /* Include the task we just executed as part of the queue size. */
if (size >= tps->stats->max_qsize) { if (size >= tps->stats.max_qsize) {
tps->stats->max_qsize = size + 1; tps->stats.max_qsize = size + 1;
}
} }
ao2_unlock(tps); ao2_unlock(tps);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment