diff options
author | Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> | 2011-11-17 13:40:26 +0000 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2011-12-05 14:51:38 +0100 |
commit | e8ee5e4c476d5b0654d8f1271a2b7c065acc486e (patch) | |
tree | e418211d889c8d3500eaf1d3f655e27e83345695 /qemu-coroutine-lock.c | |
parent | 3951690a4a29e031492090131d001e5047938631 (diff) | |
download | qemu-e8ee5e4c476d5b0654d8f1271a2b7c065acc486e.zip qemu-e8ee5e4c476d5b0654d8f1271a2b7c065acc486e.tar.gz qemu-e8ee5e4c476d5b0654d8f1271a2b7c065acc486e.tar.bz2 |
coroutine: add qemu_co_queue_restart_all()
It's common to wake up all waiting coroutines. Introduce the
qemu_co_queue_restart_all() function to do this instead of looping over
qemu_co_queue_next() in every caller.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'qemu-coroutine-lock.c')
-rw-r--r-- | qemu-coroutine-lock.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/qemu-coroutine-lock.c b/qemu-coroutine-lock.c index 9549c07..26ad76b 100644 --- a/qemu-coroutine-lock.c +++ b/qemu-coroutine-lock.c @@ -84,6 +84,13 @@ bool qemu_co_queue_next(CoQueue *queue) return (next != NULL); } +void qemu_co_queue_restart_all(CoQueue *queue) +{ + while (qemu_co_queue_next(queue)) { + /* Do nothing */ + } +} + bool qemu_co_queue_empty(CoQueue *queue) { return (QTAILQ_FIRST(&queue->entries) == NULL); @@ -144,13 +151,7 @@ void qemu_co_rwlock_unlock(CoRwlock *lock) assert(qemu_in_coroutine()); if (lock->writer) { lock->writer = false; - while (!qemu_co_queue_empty(&lock->queue)) { - /* - * Wakeup every body. This will include some - * writers too. - */ - qemu_co_queue_next(&lock->queue); - } + qemu_co_queue_restart_all(&lock->queue); } else { lock->reader--; assert(lock->reader >= 0); |