From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:38759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RAgdV-0008C7-Dt for qemu-devel@nongnu.org; Mon, 03 Oct 2011 07:24:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RAgdR-0004CV-Mx for qemu-devel@nongnu.org; Mon, 03 Oct 2011 07:24:41 -0400 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:39495) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RAgdQ-0004Bf-PP for qemu-devel@nongnu.org; Mon, 03 Oct 2011 07:24:37 -0400 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by e28smtp05.in.ibm.com (8.14.4/8.13.1) with ESMTP id p93BOWC6014530 for ; Mon, 3 Oct 2011 16:54:32 +0530 Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p93BNFj63403874 for ; Mon, 3 Oct 2011 16:53:15 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p93BNELW020924 for ; Mon, 3 Oct 2011 22:23:14 +1100 From: Harsh Prateek Bora Date: Mon, 3 Oct 2011 16:53:13 +0530 Message-Id: <1317640994-16559-2-git-send-email-harsh@linux.vnet.ibm.com> In-Reply-To: <1317640994-16559-1-git-send-email-harsh@linux.vnet.ibm.com> References: <1317640994-16559-1-git-send-email-harsh@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 1/2] Introduce QemuRWLock List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, aneesh.kumar@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 --- 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