Patchwork [1/9] Add read-write lock to QEMU

login
register
mail settings
Submitter Arun Bharadwaj
Date Oct. 14, 2010, 12:23 p.m.
Message ID <20101014122320.2238.26201.stgit@localhost6.localdomain6>
Download mbox | patch
Permalink /patch/67813/
State New
Headers show

Comments

Arun Bharadwaj - Oct. 14, 2010, 12:23 p.m.
From: Sripathi Kodi <sripathik@in.ibm.com>

Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
---
 qemu-thread.c |   40 ++++++++++++++++++++++++++++++++++++++++
 qemu-thread.h |   10 ++++++++++
 2 files changed, 50 insertions(+), 0 deletions(-)

Patch

diff --git a/qemu-thread.c b/qemu-thread.c
index fbc78fe..42774ff 100644
--- a/qemu-thread.c
+++ b/qemu-thread.c
@@ -90,6 +90,46 @@  void qemu_mutex_unlock(QemuMutex *mutex)
         error_exit(err, __func__);
 }
 
+void qemu_rwmutex_init(QemuRWMutex *mutex)
+{
+    int err;
+
+    err = pthread_rwlock_init(&mutex->lock, NULL);
+    if (err) {
+        error_exit(err, __func__);
+    }
+}
+
+void qemu_rwmutex_rdlock(QemuRWMutex *mutex)
+{
+    int err;
+
+    err = pthread_rwlock_rdlock(&mutex->lock);
+    if (err) {
+        error_exit(err, __func__);
+    }
+}
+
+void qemu_rwmutex_wrlock(QemuRWMutex *mutex)
+{
+    int err;
+
+    err = pthread_rwlock_wrlock(&mutex->lock);
+    if (err) {
+        error_exit(err, __func__);
+    }
+}
+
+void qemu_rwmutex_unlock(QemuRWMutex *mutex)
+{
+    int err;
+
+    err = pthread_rwlock_unlock(&mutex->lock);
+    if (err) {
+        error_exit(err, __func__);
+    }
+}
+
 void qemu_cond_init(QemuCond *cond)
 {
     int err;
diff --git a/qemu-thread.h b/qemu-thread.h
index 19bb30c..1b0267e 100644
--- a/qemu-thread.h
+++ b/qemu-thread.h
@@ -7,6 +7,10 @@  struct QemuMutex {
     pthread_mutex_t lock;
 };
 
+struct QemuRWMutex {
+    pthread_rwlock_t lock;
+};
+
 struct QemuCond {
     pthread_cond_t cond;
 };
@@ -16,6 +20,7 @@  struct QemuThread {
 };
 
 typedef struct QemuMutex QemuMutex;
+typedef struct QemuRWMutex QemuRWMutex;
 typedef struct QemuCond QemuCond;
 typedef struct QemuThread QemuThread;
 
@@ -26,6 +31,11 @@  int qemu_mutex_trylock(QemuMutex *mutex);
 int qemu_mutex_timedlock(QemuMutex *mutex, uint64_t msecs);
 void qemu_mutex_unlock(QemuMutex *mutex);
 
+void qemu_rwmutex_init(QemuRWMutex *mutex);
+void qemu_rwmutex_rdlock(QemuRWMutex *mutex);
+void qemu_rwmutex_wrlock(QemuRWMutex *mutex);
+void qemu_rwmutex_unlock(QemuRWMutex *mutex);
+
 void qemu_cond_init(QemuCond *cond);
 void qemu_cond_destroy(QemuCond *cond);
 void qemu_cond_signal(QemuCond *cond);