[Asterisk-code-review] taskprocessor: Do not use separate allocation for stats or n... (asterisk[master])
Joshua Colp
asteriskteam at digium.com
Wed Nov 14 07:05:12 CST 2018
Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/10618 )
Change subject: taskprocessor: Do not use separate allocation for stats or name.
......................................................................
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
---
M main/taskprocessor.c
1 file changed, 11 insertions(+), 27 deletions(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
George Joseph: Looks good to me, approved
diff --git a/main/taskprocessor.c b/main/taskprocessor.c
index 33acb37..0f183c4 100644
--- a/main/taskprocessor.c
+++ b/main/taskprocessor.c
@@ -67,10 +67,8 @@
/*! \brief A ast_taskprocessor structure is a singleton by name */
struct ast_taskprocessor {
- /*! \brief Friendly name of the taskprocessor */
- const char *name;
/*! \brief Taskprocessor statistics */
- struct tps_taskprocessor_stats *stats;
+ struct tps_taskprocessor_stats stats;
void *local_data;
/*! \brief Taskprocessor current queue size */
long tps_queue_size;
@@ -91,6 +89,8 @@
unsigned int high_water_alert:1;
/*! Indicates if the taskprocessor is currently suspended */
unsigned int suspended:1;
+ /*! \brief Friendly name of the taskprocessor */
+ char name[0];
};
/*!
@@ -515,13 +515,8 @@
while ((tps = ao2_iterator_next(&iter))) {
ast_copy_string(name, tps->name, sizeof(name));
qsize = tps->tps_queue_size;
- if (tps->stats) {
- maxqsize = tps->stats->max_qsize;
- processed = tps->stats->_tasks_processed_count;
- } else {
- maxqsize = 0;
- processed = 0;
- }
+ maxqsize = tps->stats.max_qsize;
+ processed = tps->stats._tasks_processed_count;
ast_cli(a->fd, FMT_FIELDS, name, processed, qsize, maxqsize,
tps->tps_queue_low, tps->tps_queue_high);
ast_taskprocessor_unreference(tps);
@@ -645,10 +640,6 @@
tps_alert_add(t, -1);
}
- ast_free(t->stats);
- t->stats = NULL;
- ast_free((char *) t->name);
- t->name = NULL;
ao2_cleanup(t->listener);
t->listener = NULL;
}
@@ -744,7 +735,7 @@
{
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) {
ast_log(LOG_WARNING, "failed to create taskprocessor '%s'\n", name);
return NULL;
@@ -754,12 +745,7 @@
p->tps_queue_low = (AST_TASKPROCESSOR_HIGH_WATER_LEVEL * 9) / 10;
p->tps_queue_high = AST_TASKPROCESSOR_HIGH_WATER_LEVEL;
- p->stats = ast_calloc(1, sizeof(*p->stats));
- p->name = ast_strdup(name);
- if (!p->stats || !p->name) {
- ao2_ref(p, -1);
- return NULL;
- }
+ strcpy(p->name, name); /*SAFE*/
ao2_ref(listener, +1);
p->listener = listener;
@@ -985,13 +971,11 @@
size = ast_taskprocessor_size(tps);
/* 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. */
- if (size >= tps->stats->max_qsize) {
- tps->stats->max_qsize = size + 1;
- }
+ /* Include the task we just executed as part of the queue size. */
+ if (size >= tps->stats.max_qsize) {
+ tps->stats.max_qsize = size + 1;
}
ao2_unlock(tps);
--
To view, visit https://gerrit.asterisk.org/10618
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I74fe9a7f357f0e6d63152f163cf5eef6428218e1
Gerrit-Change-Number: 10618
Gerrit-PatchSet: 2
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2 (1000185)
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181114/e0ba2697/attachment-0001.html>
More information about the asterisk-code-review
mailing list