Received: from [140.186.70.92] (port=54354 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P6MqW-0007Dt-7i for qemu-devel@nongnu.org; Thu, 14 Oct 2010 08:23:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P6MqV-0003P4-1V for qemu-devel@nongnu.org; Thu, 14 Oct 2010 08:23:44 -0400 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:49849) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P6MqU-0003Oh-GL for qemu-devel@nongnu.org; Thu, 14 Oct 2010 08:23:42 -0400 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [202.81.31.245]) by e23smtp04.au.ibm.com (8.14.4/8.13.1) with ESMTP id o9ECIrnW010299 for ; Thu, 14 Oct 2010 23:18:53 +1100 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9ECNfrM3137646 for ; Thu, 14 Oct 2010 23:23:41 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o9ECNeFb027146 for ; Thu, 14 Oct 2010 23:23:41 +1100 Received: from localhost6.localdomain6 ([9.77.206.195]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o9ECNSLg027050 for ; Thu, 14 Oct 2010 23:23:39 +1100 From: Arun R Bharadwaj Date: Thu, 14 Oct 2010 17:53:20 +0530 Message-ID: <20101014122320.2238.26201.stgit@localhost6.localdomain6> In-Reply-To: <20101014122217.2238.94995.stgit@localhost6.localdomain6> References: <20101014122217.2238.94995.stgit@localhost6.localdomain6> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 1/9] Add read-write lock to QEMU List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: Sripathi Kodi Signed-off-by: Sripathi Kodi --- qemu-thread.c | 40 ++++++++++++++++++++++++++++++++++++++++ qemu-thread.h | 10 ++++++++++ 2 files changed, 50 insertions(+), 0 deletions(-) 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);