Skip to contentSkip to conversation

thread-pool: clean up thread_pool_completion_bh()

PATCH Applied Stefan Hajnoczi 2 participants 3 messages Apr 2, 2015 – Apr 7, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thread-pool: clean up thread_pool_completion_bh()

This patch simplifies thread_pool_completion_bh().

The function first checks elem->state:

  if (elem->state != THREAD_DONE) {
      continue;
  }

It then goes on to check elem->state == THREAD_DONE although we already know this must be the case.

The QLIST_REMOVE() is duplicated down both branches of an if-else statement so that can be lifted out as well.

---
 thread-pool.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
thread-pool.c +6 -8
index e2cac8e..ac909f4 100644
@@ -170,12 +170,12 @@ restart:
         if (elem->state != THREAD_DONE) {
             continue;
         }
-        if (elem->state == THREAD_DONE) {
-            trace_thread_pool_complete(pool, elem, elem->common.opaque,
-                                       elem->ret);
-        }
-        if (elem->state == THREAD_DONE && elem->common.cb) {
-            QLIST_REMOVE(elem, all);
+
+        trace_thread_pool_complete(pool, elem, elem->common.opaque,
+                                   elem->ret);
+        QLIST_REMOVE(elem, all);
+
+        if (elem->common.cb) {
             /* Read state before ret.  */
             smp_rmb();
 
@@ -188,8 +188,6 @@ restart:
             qemu_aio_unref(elem);
             goto restart;
         } else {
-            /* remove the request */
-            QLIST_REMOVE(elem, all);
             qemu_aio_unref(elem);
         }
     }
Signature · 1 line
2.1.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Stefan Hajnoczi

This patch simplifies thread_pool_completion_bh().

The function first checks elem->state:

  if (elem->state != THREAD_DONE) {
      continue;
  }

It then goes on to check elem->state == THREAD_DONE although we already know this must be the case.

And not once, twice. :)

This was the outcome of removing THREAD_CANCELED.

Quoted 30 lines
---
 thread-pool.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
thread-pool.c +6 -6
index e2cac8e..ac909f4 100644
@@ -170,12 +170,12 @@ restart:
         if (elem->state != THREAD_DONE) {
             continue;
         }
-        if (elem->state == THREAD_DONE) {
-            trace_thread_pool_complete(pool, elem, elem->common.opaque,
-                                       elem->ret);
-        }
-        if (elem->state == THREAD_DONE && elem->common.cb) {
-            QLIST_REMOVE(elem, all);
+
+        trace_thread_pool_complete(pool, elem, elem->common.opaque,
+                                   elem->ret);
+        QLIST_REMOVE(elem, all);
+
+        if (elem->common.cb) {
             /* Read state before ret.  */
             smp_rmb();
 

thread-pool.c restart: · line 193

Quoted 8 lines
thread-pool.c +0 -2
@@ -188,8 +188,6 @@ restart:
             qemu_aio_unref(elem);
             goto restart;
         } else {
-            /* remove the request */
-            QLIST_REMOVE(elem, all);
             qemu_aio_unref(elem);
         }
     }
author Applied
#2 lore raw
In reply to Stefan Hajnoczi
Quoted 11 lines · Stefan Hajnoczi

This patch simplifies thread_pool_completion_bh().

The function first checks elem->state:

  if (elem->state != THREAD_DONE) {
      continue;
  }

It then goes on to check elem->state == THREAD_DONE although we already know this must be the case.

Quoted 7 lines

The QLIST_REMOVE() is duplicated down both branches of an if-else statement so that can be lifted out as well.

---
 thread-pool.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Thanks, applied to my block-next tree:
https://github.com/stefanha/qemu/commits/block-next

Stefan