Only use process shared mutexes on support platforms
On FreeBSD, suggest the use of threads instead.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/init.c b/init.c
index a8acdc0..3142d8c 100644
--- a/init.c
+++ b/init.c
@@ -214,6 +214,15 @@
{
struct thread_options *o = &td->o;
+#ifndef FIO_HAVE_PSHARED_MUTEX
+ if (!td->o.use_thread) {
+ log_info("fio: this platform does not support process shared"
+ " mutexes, forcing use of threads. Use the 'thread'"
+ " option to get rid of this warning.\n");
+ td->o.use_thread = 1;
+ }
+#endif
+
#ifndef FIO_HAVE_CPU_AFFINITY
if (td->o.gtod_cpu) {
log_err("fio: platform must support CPU affinity for"
diff --git a/mutex.c b/mutex.c
index 7d07218..5beaa08 100644
--- a/mutex.c
+++ b/mutex.c
@@ -22,7 +22,7 @@
struct fio_mutex *mutex = NULL;
pthread_mutexattr_t attr;
pthread_condattr_t cond;
- int fd, ret;
+ int fd, ret, mflag;
fd = mkstemp(mutex_name);
if (fd < 0) {
@@ -48,19 +48,28 @@
mutex->mutex_fd = fd;
mutex->value = value;
+ /*
+ * Not all platforms support process shared mutexes (FreeBSD)
+ */
+#ifdef FIO_HAVE_PSHARED_MUTEX
+ mflag = PTHREAD_PROCESS_SHARED;
+#else
+ mflag = PTHREAD_PROCESS_PRIVATE;
+#endif
+
ret = pthread_mutexattr_init(&attr);
if (ret) {
log_err("pthread_mutexattr_init: %s\n", strerror(ret));
goto err;
}
- ret = pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+ ret = pthread_mutexattr_setpshared(&attr, mflag);
if (ret) {
log_err("pthread_mutexattr_setpshared: %s\n", strerror(ret));
goto err;
}
pthread_condattr_init(&cond);
- pthread_condattr_setpshared(&cond, PTHREAD_PROCESS_SHARED);
+ pthread_condattr_setpshared(&cond, mflag);
pthread_cond_init(&mutex->cond, &cond);
ret = pthread_mutex_init(&mutex->lock, &attr);
diff --git a/os/os-linux.h b/os/os-linux.h
index 03d2450..a2a9b24 100644
--- a/os/os-linux.h
+++ b/os/os-linux.h
@@ -28,6 +28,7 @@
#define FIO_HAVE_STRSEP
#define FIO_HAVE_FALLOCATE
#define FIO_HAVE_POSIXAIO_FSYNC
+#define FIO_HAVE_PSHARED_MUTEX
#define OS_MAP_ANON MAP_ANONYMOUS
diff --git a/os/os-solaris.h b/os/os-solaris.h
index 51c0ff4..35148d2 100644
--- a/os/os-solaris.h
+++ b/os/os-solaris.h
@@ -10,6 +10,7 @@
#define FIO_HAVE_FALLOCATE
#define FIO_HAVE_POSIXAIO_FSYNC
#define FIO_HAVE_CPU_AFFINITY
+#define FIO_HAVE_PSHARED_MUTEX
#define OS_MAP_ANON MAP_ANON
#define OS_RAND_MAX 2147483648UL