From: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: stefanha@gmail.com, aneesh.kumar@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH 1/2] Introduce QemuRWLock
Date: Mon, 3 Oct 2011 16:53:13 +0530 [thread overview]
Message-ID: <1317640994-16559-2-git-send-email-harsh@linux.vnet.ibm.com> (raw)
In-Reply-To: <1317640994-16559-1-git-send-email-harsh@linux.vnet.ibm.com>
SynthFS introduced in
http://lists.gnu.org/archive/html/qemu-devel/2011-09/msg01206.html
uses pthread_rwlock_* APIs for rwlocks, which raise the need of a generic
Qemu specific, os independent rwlock APIs. This patch introduces the same.
Another patch to switch pthread_rwlock_* into qemu_rwlock_* follows.
Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
---
qemu-thread-posix.c | 26 ++++++++++++++++++++++++++
qemu-thread-posix.h | 4 ++++
qemu-thread.h | 6 ++++++
3 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/qemu-thread-posix.c b/qemu-thread-posix.c
index ac3c0c9..9ae7f44 100644
--- a/qemu-thread-posix.c
+++ b/qemu-thread-posix.c
@@ -147,3 +147,29 @@ void qemu_thread_exit(void *retval)
{
pthread_exit(retval);
}
+
+int qemu_rwlock_wrlock(QemuRWLock *rwlock)
+{
+ return pthread_rwlock_wrlock(&rwlock->rwl);
+}
+
+int qemu_rwlock_unlock(QemuRWLock *rwlock)
+{
+ return pthread_rwlock_unlock(&rwlock->rwl);
+}
+
+int qemu_rwlock_rdlock(QemuRWLock *rwlock)
+{
+ return pthread_rwlock_rdlock(&rwlock->rwl);
+}
+
+void qemu_rwlock_init(QemuRWLock *rwlock)
+{
+ int err;
+ pthread_rwlockattr_t rwlockattr;
+
+ pthread_rwlockattr_init(&rwlockattr);
+ err = pthread_rwlock_init(&rwlock->rwl, &rwlockattr);
+ if (err)
+ error_exit(err, __func__);
+}
diff --git a/qemu-thread-posix.h b/qemu-thread-posix.h
index ee4618e..8c1e4f6 100644
--- a/qemu-thread-posix.h
+++ b/qemu-thread-posix.h
@@ -14,4 +14,8 @@ struct QemuThread {
pthread_t thread;
};
+struct QemuRWLock {
+ pthread_rwlock_t rwl;
+};
+
#endif
diff --git a/qemu-thread.h b/qemu-thread.h
index 0a73d50..44321fb 100644
--- a/qemu-thread.h
+++ b/qemu-thread.h
@@ -6,6 +6,7 @@
typedef struct QemuMutex QemuMutex;
typedef struct QemuCond QemuCond;
typedef struct QemuThread QemuThread;
+typedef struct QemuRWLock QemuRWLock;
#ifdef _WIN32
#include "qemu-thread-win32.h"
@@ -31,6 +32,11 @@ void qemu_cond_signal(QemuCond *cond);
void qemu_cond_broadcast(QemuCond *cond);
void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex);
+void qemu_rwlock_init(QemuRWLock *rwlock);
+int qemu_rwlock_rdlock(QemuRWLock *rwlock);
+int qemu_rwlock_wrlock(QemuRWLock *rwlock);
+int qemu_rwlock_unlock(QemuRWLock *rwlock);
+
void qemu_thread_create(QemuThread *thread,
void *(*start_routine)(void*),
void *arg);
--
1.7.4.1
next prev parent reply other threads:[~2011-10-03 11:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-03 11:23 [Qemu-devel] [PATCH 0/2] Introduce QemuRWLock Harsh Prateek Bora
2011-10-03 11:23 ` Harsh Prateek Bora [this message]
2011-10-03 11:23 ` [Qemu-devel] [PATCH 2/2] Use qemu_rwlock_* interface instead of pthread_rwlock_* Harsh Prateek Bora
2011-10-03 12:16 ` [Qemu-devel] [PATCH 0/2] Introduce QemuRWLock Jan Kiszka
2011-10-03 17:30 ` Aneesh Kumar K.V
2011-10-03 17:50 ` Jan Kiszka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1317640994-16559-2-git-send-email-harsh@linux.vnet.ibm.com \
--to=harsh@linux.vnet.ibm.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).