<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10470">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">threadpool: Eliminate pointless AO2 usage.<br><br>thread_worker_pair, set_size_data and task_pushed_data structures are<br>allocated with AO2 objects, passed to a taskprocessor, then released.<br>They never have multiple owners or use locking so AO2 only adds<br>overhead.<br><br>Change-Id: I2204d2615d9d952670fcb48e0a9c0dd1a6ba5036<br>---<br>M main/threadpool.c<br>1 file changed, 14 insertions(+), 11 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/70/10470/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/threadpool.c b/main/threadpool.c</span><br><span>index e3d0e40..2306d59 100644</span><br><span>--- a/main/threadpool.c</span><br><span>+++ b/main/threadpool.c</span><br><span>@@ -200,10 +200,10 @@</span><br><span> /*!</span><br><span> * \brief Destructor for thread_worker_pair</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">-static void thread_worker_pair_destructor(void *obj)</span><br><span style="color: hsl(120, 100%, 40%);">+static void thread_worker_pair_free(struct thread_worker_pair *pair)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- struct thread_worker_pair *pair = obj;</span><br><span> ao2_ref(pair->worker, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(pair);</span><br><span> }</span><br><span> </span><br><span> /*!</span><br><span>@@ -214,13 +214,14 @@</span><br><span> static struct thread_worker_pair *thread_worker_pair_alloc(struct ast_threadpool *pool,</span><br><span> struct worker_thread *worker)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- struct thread_worker_pair *pair = ao2_alloc(sizeof(*pair), thread_worker_pair_destructor);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct thread_worker_pair *pair = ast_malloc(sizeof(*pair));</span><br><span> if (!pair) {</span><br><span> return NULL;</span><br><span> }</span><br><span> pair->pool = pool;</span><br><span> ao2_ref(worker, +1);</span><br><span> pair->worker = worker;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> return pair;</span><br><span> }</span><br><span> </span><br><span>@@ -240,7 +241,7 @@</span><br><span> </span><br><span> threadpool_send_state_changed(pair->pool);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(pair, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ thread_worker_pair_free(pair);</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span>@@ -282,7 +283,7 @@</span><br><span> ao2_unlink(pair->pool->zombie_threads, pair->worker);</span><br><span> threadpool_send_state_changed(pair->pool);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(pair, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ thread_worker_pair_free(pair);</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span>@@ -314,7 +315,7 @@</span><br><span> ao2_unlink(pair->pool->idle_threads, pair->worker);</span><br><span> threadpool_send_state_changed(pair->pool);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(pair, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ thread_worker_pair_free(pair);</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span>@@ -447,7 +448,7 @@</span><br><span> static struct task_pushed_data *task_pushed_data_alloc(struct ast_threadpool *pool,</span><br><span> int was_empty)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- struct task_pushed_data *tpd = ao2_alloc(sizeof(*tpd), NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct task_pushed_data *tpd = ast_malloc(sizeof(*tpd));</span><br><span> </span><br><span> if (!tpd) {</span><br><span> return NULL;</span><br><span>@@ -549,6 +550,8 @@</span><br><span> int was_empty = tpd->was_empty;</span><br><span> unsigned int existing_active;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(tpd);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (pool->listener && pool->listener->callbacks->task_pushed) {</span><br><span> pool->listener->callbacks->task_pushed(pool, pool->listener, was_empty);</span><br><span> }</span><br><span>@@ -565,7 +568,6 @@</span><br><span> /* If no idle threads could be transitioned to active grow the pool as permitted. */</span><br><span> if (ao2_container_count(pool->active_threads) == existing_active) {</span><br><span> if (!pool->options.auto_increment) {</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(tpd, -1);</span><br><span> return 0;</span><br><span> }</span><br><span> grow(pool, pool->options.auto_increment);</span><br><span>@@ -575,7 +577,6 @@</span><br><span> }</span><br><span> </span><br><span> threadpool_send_state_changed(pool);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(tpd, -1);</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span>@@ -790,7 +791,7 @@</span><br><span> static struct set_size_data *set_size_data_alloc(struct ast_threadpool *pool,</span><br><span> unsigned int size)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- struct set_size_data *ssd = ao2_alloc(sizeof(*ssd), NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct set_size_data *ssd = ast_malloc(sizeof(*ssd));</span><br><span> if (!ssd) {</span><br><span> return NULL;</span><br><span> }</span><br><span>@@ -813,7 +814,7 @@</span><br><span> */</span><br><span> static int queued_set_size(void *data)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- RAII_VAR(struct set_size_data *, ssd, data, ao2_cleanup);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct set_size_data *ssd = data;</span><br><span> struct ast_threadpool *pool = ssd->pool;</span><br><span> unsigned int num_threads = ssd->size;</span><br><span> </span><br><span>@@ -821,6 +822,8 @@</span><br><span> unsigned int current_size = ao2_container_count(pool->active_threads) +</span><br><span> ao2_container_count(pool->idle_threads);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(ssd);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (current_size == num_threads) {</span><br><span> ast_debug(3, "Not changing threadpool size since new size %u is the same as current %u\n",</span><br><span> num_threads, current_size);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10470">change 10470</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/10470"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I2204d2615d9d952670fcb48e0a9c0dd1a6ba5036 </div>
<div style="display:none"> Gerrit-Change-Number: 10470 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>