qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 14/32] coroutine: use QSIMPLEQ instead of QTAILQ
Date: Fri,  8 Jul 2016 19:21:26 +0200	[thread overview]
Message-ID: <1467998504-15744-15-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1467998504-15744-1-git-send-email-kwolf@redhat.com>

From: Paolo Bonzini <pbonzini@redhat.com>

CoQueue do not need to remove any element but the head of the list;
processing is always strictly FIFO.  Therefore, the simpler singly-linked
QSIMPLEQ can be used instead.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 include/qemu/coroutine.h     |  2 +-
 include/qemu/coroutine_int.h |  4 ++--
 util/qemu-coroutine-lock.c   | 22 +++++++++++-----------
 util/qemu-coroutine.c        |  2 +-
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
index 305fe76..63ae7fe 100644
--- a/include/qemu/coroutine.h
+++ b/include/qemu/coroutine.h
@@ -102,7 +102,7 @@ bool qemu_in_coroutine(void);
  * are built.
  */
 typedef struct CoQueue {
-    QTAILQ_HEAD(, Coroutine) entries;
+    QSIMPLEQ_HEAD(, Coroutine) entries;
 } CoQueue;
 
 /**
diff --git a/include/qemu/coroutine_int.h b/include/qemu/coroutine_int.h
index 42d6838..581a7f5 100644
--- a/include/qemu/coroutine_int.h
+++ b/include/qemu/coroutine_int.h
@@ -41,8 +41,8 @@ struct Coroutine {
     QSLIST_ENTRY(Coroutine) pool_next;
 
     /* Coroutines that should be woken up when we yield or terminate */
-    QTAILQ_HEAD(, Coroutine) co_queue_wakeup;
-    QTAILQ_ENTRY(Coroutine) co_queue_next;
+    QSIMPLEQ_HEAD(, Coroutine) co_queue_wakeup;
+    QSIMPLEQ_ENTRY(Coroutine) co_queue_next;
 };
 
 Coroutine *qemu_coroutine_new(void);
diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c
index da37ca7..cf53693 100644
--- a/util/qemu-coroutine-lock.c
+++ b/util/qemu-coroutine-lock.c
@@ -31,13 +31,13 @@
 
 void qemu_co_queue_init(CoQueue *queue)
 {
-    QTAILQ_INIT(&queue->entries);
+    QSIMPLEQ_INIT(&queue->entries);
 }
 
 void coroutine_fn qemu_co_queue_wait(CoQueue *queue)
 {
     Coroutine *self = qemu_coroutine_self();
-    QTAILQ_INSERT_TAIL(&queue->entries, self, co_queue_next);
+    QSIMPLEQ_INSERT_TAIL(&queue->entries, self, co_queue_next);
     qemu_coroutine_yield();
     assert(qemu_in_coroutine());
 }
@@ -55,8 +55,8 @@ void qemu_co_queue_run_restart(Coroutine *co)
     Coroutine *next;
 
     trace_qemu_co_queue_run_restart(co);
-    while ((next = QTAILQ_FIRST(&co->co_queue_wakeup))) {
-        QTAILQ_REMOVE(&co->co_queue_wakeup, next, co_queue_next);
+    while ((next = QSIMPLEQ_FIRST(&co->co_queue_wakeup))) {
+        QSIMPLEQ_REMOVE_HEAD(&co->co_queue_wakeup, co_queue_next);
         qemu_coroutine_enter(next, NULL);
     }
 }
@@ -66,13 +66,13 @@ static bool qemu_co_queue_do_restart(CoQueue *queue, bool single)
     Coroutine *self = qemu_coroutine_self();
     Coroutine *next;
 
-    if (QTAILQ_EMPTY(&queue->entries)) {
+    if (QSIMPLEQ_EMPTY(&queue->entries)) {
         return false;
     }
 
-    while ((next = QTAILQ_FIRST(&queue->entries)) != NULL) {
-        QTAILQ_REMOVE(&queue->entries, next, co_queue_next);
-        QTAILQ_INSERT_TAIL(&self->co_queue_wakeup, next, co_queue_next);
+    while ((next = QSIMPLEQ_FIRST(&queue->entries)) != NULL) {
+        QSIMPLEQ_REMOVE_HEAD(&queue->entries, co_queue_next);
+        QSIMPLEQ_INSERT_TAIL(&self->co_queue_wakeup, next, co_queue_next);
         trace_qemu_co_queue_next(next);
         if (single) {
             break;
@@ -97,19 +97,19 @@ bool qemu_co_enter_next(CoQueue *queue)
 {
     Coroutine *next;
 
-    next = QTAILQ_FIRST(&queue->entries);
+    next = QSIMPLEQ_FIRST(&queue->entries);
     if (!next) {
         return false;
     }
 
-    QTAILQ_REMOVE(&queue->entries, next, co_queue_next);
+    QSIMPLEQ_REMOVE_HEAD(&queue->entries, co_queue_next);
     qemu_coroutine_enter(next, NULL);
     return true;
 }
 
 bool qemu_co_queue_empty(CoQueue *queue)
 {
-    return QTAILQ_FIRST(&queue->entries) == NULL;
+    return QSIMPLEQ_FIRST(&queue->entries) == NULL;
 }
 
 void qemu_co_mutex_init(CoMutex *mutex)
diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c
index 5816702..b7cb636 100644
--- a/util/qemu-coroutine.c
+++ b/util/qemu-coroutine.c
@@ -76,7 +76,7 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry)
     }
 
     co->entry = entry;
-    QTAILQ_INIT(&co->co_queue_wakeup);
+    QSIMPLEQ_INIT(&co->co_queue_wakeup);
     return co;
 }
 
-- 
1.8.3.1

  parent reply	other threads:[~2016-07-08 17:22 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-08 17:21 [Qemu-devel] [PULL 00/32] Block layer patches Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 01/32] stream: Fix prototype of stream_start() Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 02/32] blockjob: Update description of the 'id' field Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 03/32] blockjob: Add block_job_get() Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 04/32] block: Use block_job_get() in find_block_job() Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 05/32] blockjob: Add 'job_id' parameter to block_job_create() Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 06/32] mirror: Add 'job-id' parameter to 'blockdev-mirror' and 'drive-mirror' Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 07/32] backup: Add 'job-id' parameter to 'blockdev-backup' and 'drive-backup' Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 08/32] stream: Add 'job-id' parameter to 'block-stream' Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 09/32] commit: Add 'job-id' parameter to 'block-commit' Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 10/32] qemu-img: Set the ID of the block job in img_commit() Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 11/32] blockjob: Update description of the 'device' field in the QMP API Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 12/32] osdep: Introduce qemu_dup Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 13/32] raw-posix: Use qemu_dup Kevin Wolf
2016-07-08 17:21 ` Kevin Wolf [this message]
2016-07-08 17:21 ` [Qemu-devel] [PULL 15/32] test-coroutine: prepare for the next patch Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 16/32] coroutine: move entry argument to qemu_coroutine_create Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 17/32] block/qdev: Allow node name for drive properties Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 18/32] block/qdev: Allow configuring WCE with qdev properties Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 19/32] commit: Fix use of error handling policy Kevin Wolf
2016-07-08 21:36   ` [Qemu-devel] [Qemu-block] " Eric Blake
2016-07-11 11:22     ` Kevin Wolf
2016-07-11 11:40       ` [Qemu-devel] " Paolo Bonzini
2016-07-11 12:37         ` Kevin Wolf
2016-07-11 11:57       ` [Qemu-devel] [Qemu-block] " Max Reitz
2016-07-08 17:21 ` [Qemu-devel] [PULL 20/32] block/qdev: Allow configuring rerror/werror with qdev properties Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 21/32] qemu-iotests: Test setting WCE with qdev Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 22/32] block: Remove BB options from blockdev-add Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 23/32] qemu-img: Use strerror() for generic resize error Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 24/32] qcow2: Avoid making the L1 table too big Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 25/32] qemu-io: Use correct range limitations Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 26/32] qcow2: Fix qcow2_get_cluster_offset() Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 27/32] Improve block job rate limiting for small bandwidth values Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 28/32] vmdk: fix metadata write regression Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 29/32] blockdev: Fix regression with the default naming of throttling groups Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 30/32] qemu-iotests: Test " Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 31/32] hmp: use snapshot name to determine whether a snapshot is 'fully available' Kevin Wolf
2016-07-08 17:21 ` [Qemu-devel] [PULL 32/32] hmp: show all of snapshot info on every block dev in output of 'info snapshots' Kevin Wolf
2016-07-11 16:14 ` [Qemu-devel] [PULL 00/32] Block layer patches Peter Maydell
2016-07-11 16:25   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1467998504-15744-15-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).