qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH -V2] coroutine: Add CoRwlock support
@ 2011-07-27 16:21 Aneesh Kumar K.V
  2011-07-29 12:53 ` Kevin Wolf
  0 siblings, 1 reply; 4+ messages in thread
From: Aneesh Kumar K.V @ 2011-07-27 16:21 UTC (permalink / raw)
  To: qemu-devel, Kevin Wolf; +Cc: aliguori, Aneesh Kumar K.V

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 qemu-coroutine-lock.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 qemu-coroutine.h      |   12 ++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/qemu-coroutine-lock.c b/qemu-coroutine-lock.c
index 5071fb8..b7d01d1 100644
--- a/qemu-coroutine-lock.c
+++ b/qemu-coroutine-lock.c
@@ -115,3 +115,47 @@ void qemu_co_mutex_unlock(CoMutex *mutex)
 
     trace_qemu_co_mutex_unlock_return(mutex, self);
 }
+
+void qemu_co_rwlock_init(CoRwlock *lock)
+{
+    memset(lock, 0, sizeof(*lock));
+    qemu_co_queue_init(&lock->queue);
+}
+
+void qemu_co_rwlock_rdlock(CoRwlock *lock)
+{
+    while (lock->writer) {
+        qemu_co_queue_wait(&lock->queue);
+    }
+    lock->reader++;
+}
+
+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);
+        }
+    } else {
+        lock->reader--;
+        assert(lock->reader >= 0);
+        /* Wakeup only one waiting writer */
+        if (!lock->reader) {
+            qemu_co_queue_next(&lock->queue);
+        }
+    }
+}
+
+void qemu_co_rwlock_wrlock(CoRwlock *lock)
+{
+    while (lock->writer || lock->reader) {
+        qemu_co_queue_wait(&lock->queue);
+    }
+    lock->writer = true;
+}
diff --git a/qemu-coroutine.h b/qemu-coroutine.h
index 71cfa5a..a9735fb 100644
--- a/qemu-coroutine.h
+++ b/qemu-coroutine.h
@@ -17,6 +17,7 @@
 #include <stdbool.h>
 
 #include "qemu-queue.h"
+#include "qemu-thread.h"
 
 /**
  * Coroutines are a mechanism for stack switching and can be used for
@@ -114,4 +115,15 @@ void qemu_co_mutex_init(CoMutex *mutex);
 void qemu_co_mutex_lock(CoMutex *mutex);
 void qemu_co_mutex_unlock(CoMutex *mutex);
 
+typedef struct CoRwlock {
+    bool writer;
+    int reader;
+    CoQueue queue;
+} CoRwlock;
+
+void qemu_co_rwlock_init(CoRwlock *lock);
+void qemu_co_rwlock_rdlock(CoRwlock *lock);
+void qemu_co_rwlock_wrlock(CoRwlock *lock);
+void qemu_co_rwlock_unlock(CoRwlock *lock);
+
 #endif /* QEMU_COROUTINE_H */
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH -V2] coroutine: Add CoRwlock support
  2011-07-27 16:21 [Qemu-devel] [PATCH -V2] coroutine: Add CoRwlock support Aneesh Kumar K.V
@ 2011-07-29 12:53 ` Kevin Wolf
  2011-07-29 14:24   ` Aneesh Kumar K.V
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin Wolf @ 2011-07-29 12:53 UTC (permalink / raw)
  To: Aneesh Kumar K.V; +Cc: aliguori, qemu-devel

Am 27.07.2011 18:21, schrieb Aneesh Kumar K.V:
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> ---
>  qemu-coroutine-lock.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
>  qemu-coroutine.h      |   12 ++++++++++++
>  2 files changed, 56 insertions(+), 0 deletions(-)

Looks good to me.

What's your plan with getting this merged? Are you going to just include
it with another series that you'll send once the basic coroutine support
is in?

Kevin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH -V2] coroutine: Add CoRwlock support
  2011-07-29 12:53 ` Kevin Wolf
@ 2011-07-29 14:24   ` Aneesh Kumar K.V
  2011-07-29 15:32     ` Kevin Wolf
  0 siblings, 1 reply; 4+ messages in thread
From: Aneesh Kumar K.V @ 2011-07-29 14:24 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: aliguori, qemu-devel

On Fri, 29 Jul 2011 14:53:14 +0200, Kevin Wolf <kwolf@redhat.com> wrote:
> Am 27.07.2011 18:21, schrieb Aneesh Kumar K.V:
> > Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> > ---
> >  qemu-coroutine-lock.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
> >  qemu-coroutine.h      |   12 ++++++++++++
> >  2 files changed, 56 insertions(+), 0 deletions(-)
> 
> Looks good to me.
> 
> What's your plan with getting this merged? Are you going to just include
> it with another series that you'll send once the basic coroutine support
> is in?

Since the patch already is dependent on CoQueue, it would be nice if you
can push it through your tree. I will stage the dependent VirtFS patch
after that get merged upstream.

-aneesh

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH -V2] coroutine: Add CoRwlock support
  2011-07-29 14:24   ` Aneesh Kumar K.V
@ 2011-07-29 15:32     ` Kevin Wolf
  0 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2011-07-29 15:32 UTC (permalink / raw)
  To: Aneesh Kumar K.V; +Cc: aliguori, qemu-devel

Am 29.07.2011 16:24, schrieb Aneesh Kumar K.V:
> On Fri, 29 Jul 2011 14:53:14 +0200, Kevin Wolf <kwolf@redhat.com> wrote:
>> Am 27.07.2011 18:21, schrieb Aneesh Kumar K.V:
>>> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
>>> ---
>>>  qemu-coroutine-lock.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
>>>  qemu-coroutine.h      |   12 ++++++++++++
>>>  2 files changed, 56 insertions(+), 0 deletions(-)
>>
>> Looks good to me.
>>
>> What's your plan with getting this merged? Are you going to just include
>> it with another series that you'll send once the basic coroutine support
>> is in?
> 
> Since the patch already is dependent on CoQueue, it would be nice if you
> can push it through your tree. I will stage the dependent VirtFS patch
> after that get merged upstream.

Okay, I applied it to my branch so that I won't forget about it, but
while merging I noticed two things that you could fix: The patch adds an
#include "qemu-thread.h" to qemu-coroutine.h for apparently no reason,
and it would be nice to have comments in qemu-coroutine.h like all other
functions have.

Kevin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-07-29 15:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-27 16:21 [Qemu-devel] [PATCH -V2] coroutine: Add CoRwlock support Aneesh Kumar K.V
2011-07-29 12:53 ` Kevin Wolf
2011-07-29 14:24   ` Aneesh Kumar K.V
2011-07-29 15:32     ` Kevin Wolf

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).