<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10618">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
  George Joseph: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">taskprocessor: Do not use separate allocation for stats or name.<br><br>Merge storage for the stats object and name string into the main<br>allocation for struct ast_taskprocessor.<br><br>Change-Id: I74fe9a7f357f0e6d63152f163cf5eef6428218e1<br>---<br>M main/taskprocessor.c<br>1 file changed, 11 insertions(+), 27 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/taskprocessor.c b/main/taskprocessor.c</span><br><span>index 33acb37..0f183c4 100644</span><br><span>--- a/main/taskprocessor.c</span><br><span>+++ b/main/taskprocessor.c</span><br><span>@@ -67,10 +67,8 @@</span><br><span> </span><br><span> /*! \brief A ast_taskprocessor structure is a singleton by name */</span><br><span> struct ast_taskprocessor {</span><br><span style="color: hsl(0, 100%, 40%);">-       /*! \brief Friendly name of the taskprocessor */</span><br><span style="color: hsl(0, 100%, 40%);">-        const char *name;</span><br><span>    /*! \brief Taskprocessor statistics */</span><br><span style="color: hsl(0, 100%, 40%);">-  struct tps_taskprocessor_stats *stats;</span><br><span style="color: hsl(120, 100%, 40%);">+        struct tps_taskprocessor_stats stats;</span><br><span>        void *local_data;</span><br><span>    /*! \brief Taskprocessor current queue size */</span><br><span>       long tps_queue_size;</span><br><span>@@ -91,6 +89,8 @@</span><br><span>     unsigned int high_water_alert:1;</span><br><span>     /*! Indicates if the taskprocessor is currently suspended */</span><br><span>         unsigned int suspended:1;</span><br><span style="color: hsl(120, 100%, 40%);">+     /*! \brief Friendly name of the taskprocessor */</span><br><span style="color: hsl(120, 100%, 40%);">+      char name[0];</span><br><span> };</span><br><span> </span><br><span> /*!</span><br><span>@@ -515,13 +515,8 @@</span><br><span>        while ((tps = ao2_iterator_next(&iter))) {</span><br><span>               ast_copy_string(name, tps->name, sizeof(name));</span><br><span>           qsize = tps->tps_queue_size;</span><br><span style="color: hsl(0, 100%, 40%);">-         if (tps->stats) {</span><br><span style="color: hsl(0, 100%, 40%);">-                    maxqsize = tps->stats->max_qsize;</span><br><span style="color: hsl(0, 100%, 40%);">-                 processed = tps->stats->_tasks_processed_count;</span><br><span style="color: hsl(0, 100%, 40%);">-           } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                        maxqsize = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-                   processed = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-          }</span><br><span style="color: hsl(120, 100%, 40%);">+             maxqsize = tps->stats.max_qsize;</span><br><span style="color: hsl(120, 100%, 40%);">+           processed = tps->stats._tasks_processed_count;</span><br><span>            ast_cli(a->fd, FMT_FIELDS, name, processed, qsize, maxqsize,</span><br><span>                      tps->tps_queue_low, tps->tps_queue_high);</span><br><span>              ast_taskprocessor_unreference(tps);</span><br><span>@@ -645,10 +640,6 @@</span><br><span>           tps_alert_add(t, -1);</span><br><span>        }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   ast_free(t->stats);</span><br><span style="color: hsl(0, 100%, 40%);">-  t->stats = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-     ast_free((char *) t->name);</span><br><span style="color: hsl(0, 100%, 40%);">-  t->name = NULL;</span><br><span>   ao2_cleanup(t->listener);</span><br><span>         t->listener = NULL;</span><br><span> }</span><br><span>@@ -744,7 +735,7 @@</span><br><span> {</span><br><span>       struct ast_taskprocessor *p;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-        p = ao2_alloc(sizeof(*p), tps_taskprocessor_dtor);</span><br><span style="color: hsl(120, 100%, 40%);">+    p = ao2_alloc(sizeof(*p) + strlen(name) + 1, tps_taskprocessor_dtor);</span><br><span>        if (!p) {</span><br><span>            ast_log(LOG_WARNING, "failed to create taskprocessor '%s'\n", name);</span><br><span>               return NULL;</span><br><span>@@ -754,12 +745,7 @@</span><br><span>  p->tps_queue_low = (AST_TASKPROCESSOR_HIGH_WATER_LEVEL * 9) / 10;</span><br><span>         p->tps_queue_high = AST_TASKPROCESSOR_HIGH_WATER_LEVEL;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-  p->stats = ast_calloc(1, sizeof(*p->stats));</span><br><span style="color: hsl(0, 100%, 40%);">-      p->name = ast_strdup(name);</span><br><span style="color: hsl(0, 100%, 40%);">-  if (!p->stats || !p->name) {</span><br><span style="color: hsl(0, 100%, 40%);">-              ao2_ref(p, -1);</span><br><span style="color: hsl(0, 100%, 40%);">-         return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-    }</span><br><span style="color: hsl(120, 100%, 40%);">+     strcpy(p->name, name); /*SAFE*/</span><br><span> </span><br><span>       ao2_ref(listener, +1);</span><br><span>       p->listener = listener;</span><br><span>@@ -985,13 +971,11 @@</span><br><span>   size = ast_taskprocessor_size(tps);</span><br><span> </span><br><span>      /* Update the stats */</span><br><span style="color: hsl(0, 100%, 40%);">-  if (tps->stats) {</span><br><span style="color: hsl(0, 100%, 40%);">-            ++tps->stats->_tasks_processed_count;</span><br><span style="color: hsl(120, 100%, 40%);">+   ++tps->stats._tasks_processed_count;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-             /* Include the task we just executed as part of the queue size. */</span><br><span style="color: hsl(0, 100%, 40%);">-              if (size >= tps->stats->max_qsize) {</span><br><span style="color: hsl(0, 100%, 40%);">-                   tps->stats->max_qsize = size + 1;</span><br><span style="color: hsl(0, 100%, 40%);">-         }</span><br><span style="color: hsl(120, 100%, 40%);">+     /* Include the task we just executed as part of the queue size. */</span><br><span style="color: hsl(120, 100%, 40%);">+    if (size >= tps->stats.max_qsize) {</span><br><span style="color: hsl(120, 100%, 40%);">+             tps->stats.max_qsize = size + 1;</span><br><span>  }</span><br><span>    ao2_unlock(tps);</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10618">change 10618</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/10618"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I74fe9a7f357f0e6d63152f163cf5eef6428218e1 </div>
<div style="display:none"> Gerrit-Change-Number: 10618 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>