From 33980f5de15c4dc79dc847410fbbc64405a45617 Mon Sep 17 00:00:00 2001 From: Shaohua Li Date: Thu, 28 Mar 2013 08:28:51 -0600 Subject: [PATCH] mutex: set pshared attributes on rw semaphore Signed-off-by: Jens Axboe --- mutex.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/mutex.c b/mutex.c index 6022cdd7..5a65e53a 100644 --- a/mutex.c +++ b/mutex.c @@ -180,6 +180,7 @@ void fio_rwlock_remove(struct fio_rwlock *lock) struct fio_rwlock *fio_rwlock_init(void) { struct fio_rwlock *lock; + pthread_rwlockattr_t attr; int ret; lock = (void *) mmap(NULL, sizeof(struct fio_rwlock), @@ -193,13 +194,30 @@ struct fio_rwlock *fio_rwlock_init(void) lock->magic = FIO_RWLOCK_MAGIC; - ret = pthread_rwlock_init(&lock->lock, NULL); + ret = pthread_rwlockattr_init(&attr); if (ret) { log_err("pthread_rwlock_init: %s\n", strerror(ret)); goto err; } +#ifdef FIO_HAVE_PSHARED_MUTEX + ret = pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); + if (ret) { + log_err("pthread_rwlock_init: %s\n", strerror(ret)); + goto destroy_attr; + } +#endif + + ret = pthread_rwlock_init(&lock->lock, &attr); + if (ret) { + log_err("pthread_rwlock_init: %s\n", strerror(ret)); + goto destroy_attr; + } + + pthread_rwlockattr_destroy(&attr); return lock; +destroy_attr: + pthread_rwlockattr_destroy(&attr); err: if (lock) fio_rwlock_remove(lock); -- 2.25.1