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 <ha...@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