[Asterisk-code-review] taskprocessor: Do not use separate allocation for stats. (asterisk[master])

Corey Farrell asteriskteam at digium.com
Mon Nov 12 05:54:37 CST 2018


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/10618


Change subject: taskprocessor: Do not use separate allocation for stats.
......................................................................

taskprocessor: Do not use separate allocation for stats.

Merge the stats object into struct ast_taskprocessor.

Change-Id: I74fe9a7f357f0e6d63152f163cf5eef6428218e1
---
M main/taskprocessor.c
1 file changed, 8 insertions(+), 18 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/18/10618/1

diff --git a/main/taskprocessor.c b/main/taskprocessor.c
index 33acb37..2629eab 100644
--- a/main/taskprocessor.c
+++ b/main/taskprocessor.c
@@ -70,7 +70,7 @@
 	/*! \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;
@@ -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,8 +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);
@@ -754,9 +747,8 @@
 	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) {
+	if (!p->name) {
 		ao2_ref(p, -1);
 		return NULL;
 	}
@@ -985,13 +977,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: newchange
Gerrit-Change-Id: I74fe9a7f357f0e6d63152f163cf5eef6428218e1
Gerrit-Change-Number: 10618
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181112/82182246/attachment-0001.html>


More information about the asterisk-code-review mailing list