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>
This commit is contained in:
Paolo Bonzini
2017-02-13 19:12:44 +01:00
committed by Stefan Hajnoczi
parent 1ace7ceac5
commit a7b91d35ba
2 changed files with 26 additions and 12 deletions

View File

@ -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;