summaryrefslogtreecommitdiff
path: root/include/qemu/coroutine.h
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2017-02-13 19:12:44 +0100
committerStefan Hajnoczi <stefanha@redhat.com>2017-02-21 11:39:40 +0000
commita7b91d35bab97a2d3e779d0c64c9b837b52a6cf7 (patch)
treeadb74f4b9f4dd306e33196dc2107aeabe7e9a42a /include/qemu/coroutine.h
parent1ace7ceac507d90d50ecb2e13f7222beadb64d92 (diff)
downloadqemu-a7b91d35bab97a2d3e779d0c64c9b837b52a6cf7.tar.gz
coroutine-lock: make CoRwlock thread-safe and fair
This adds a CoMutex around the existing CoQueue. Because the write-side can just take CoMutex, the old "writer" field is not necessary anymore. Instead of removing it altogether, count the number of pending writers during a read-side critical section and forbid further readers from entering. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Message-id: 20170213181244.16297-7-pbonzini@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'include/qemu/coroutine.h')
-rw-r--r--include/qemu/coroutine.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
index d2de268981..e60beaff81 100644
--- a/include/qemu/coroutine.h
+++ b/include/qemu/coroutine.h
@@ -204,8 +204,9 @@ bool qemu_co_queue_empty(CoQueue *queue);
typedef struct CoRwlock {
- bool writer;
+ int pending_writer;
int reader;
+ CoMutex mutex;
CoQueue queue;
} CoRwlock;