configure: add generic pshared mutex test
authorSitsofe Wheeler <sitsofe@yahoo.com>
Sun, 26 Feb 2017 11:47:28 +0000 (11:47 +0000)
committerSitsofe Wheeler <sitsofe@yahoo.com>
Tue, 14 Mar 2017 10:52:42 +0000 (10:52 +0000)
Add a feature test to configure to determine if a platform has
interprocess synchronization primitives that work with threads and
remove the hardcoded enablement in the individual os/os-* headers. This
should work better for platforms where support was overlooked or didn't
exist at some point in the past but has since been added. Also update
the README to not single out FreeBSD for being thread only as this might
change...

This is based off work by the Boost project
(https://github.com/boostorg/interprocess/blob/boost-1.63.0/include/boost/interprocess/detail/workaround.hpp#L45
) that found that OSX 10.6 and Cygwin are buggy even though
_POSIX_THREAD_PROCESS_SHARED says this feature should be work on them.

Signed-off-by: Sitsofe Wheeler <sitsofe@yahoo.com>
README
configure
init.c
mutex.c
os/os-aix.h
os/os-android.h
os/os-freebsd.h
os/os-hpux.h
os/os-linux.h
os/os-solaris.h

diff --git a/README b/README
index 9493c2a5caf9af03f655866c40163c6a21bd598e..951550b83f141a1f0063cb563650f4906644f090 100644 (file)
--- a/README
+++ b/README
@@ -205,10 +205,10 @@ implemented, I'd be happy to take patches for that. An example of that is disk
 utility statistics and (I think) huge page support, support for that does exist
 in FreeBSD/Solaris.
 
-Fio uses pthread mutexes for signalling and locking and FreeBSD does not
-support process shared pthread mutexes. As a result, only threads are
-supported on FreeBSD. This could be fixed with sysv ipc locking or
-other locking alternatives.
+Fio uses pthread mutexes for signalling and locking and some platforms do not
+support process shared pthread mutexes. As a result, on such platforms only
+threads are supported. This could be fixed with sysv ipc locking or other
+locking alternatives.
 
 Other \*BSD platforms are untested, but fio should work there almost out of the
 box. Since I don't do test runs or even compiles on those platforms, your
index a7610b15a0d8bd26c2d91deb8b97e9f553e8db28..93351242a5c5e30b1e9459e14c09fb9d4f240c89 100755 (executable)
--- a/configure
+++ b/configure
@@ -604,6 +604,34 @@ EOF
 fi
 echo "POSIX AIO fsync               $posix_aio_fsync"
 
+##########################################
+# POSIX pshared attribute probe
+posix_pshared="no"
+cat > $TMPC <<EOF
+#include <unistd.h>
+int main(void)
+{
+#if defined(_POSIX_THREAD_PROCESS_SHARED) && ((_POSIX_THREAD_PROCESS_SHARED + 0) > 0)
+# if defined(__CYGWIN__)
+#  error "_POSIX_THREAD_PROCESS_SHARED is buggy on Cygwin"
+# elif defined(__APPLE__)
+#  include <AvailabilityMacros.h>
+#  include <TargetConditionals.h>
+#  if TARGET_OS_MAC && MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+#   error "_POSIX_THREAD_PROCESS_SHARED is buggy/unsupported prior to OSX 10.7"
+#  endif
+# endif
+#else
+# error "_POSIX_THREAD_PROCESS_SHARED is unsupported"
+#endif
+  return 0;
+}
+EOF
+if compile_prog "" "$LIBS" "posix_pshared" ; then
+  posix_pshared=yes
+fi
+echo "POSIX pshared support         $posix_pshared"
+
 ##########################################
 # solaris aio probe
 if test "$solaris_aio" != "yes" ; then
@@ -1986,6 +2014,9 @@ fi
 if test "$posix_aio_fsync" = "yes" ; then
   output_sym "CONFIG_POSIXAIO_FSYNC"
 fi
+if test "$posix_pshared" = "yes" ; then
+  output_sym "CONFIG_PSHARED"
+fi
 if test "$linux_fallocate" = "yes" ; then
   output_sym "CONFIG_LINUX_FALLOCATE"
 fi
diff --git a/init.c b/init.c
index 18538de1537d285623007dc975acf953dc1fce17..54fdb92a4e91c5ecb09812fea9e82b94a23bea8e 100644 (file)
--- a/init.c
+++ b/init.c
@@ -586,7 +586,7 @@ static int fixup_options(struct thread_data *td)
        struct thread_options *o = &td->o;
        int ret = 0;
 
-#ifndef FIO_HAVE_PSHARED_MUTEX
+#ifndef CONFIG_PSHARED
        if (!o->use_thread) {
                log_info("fio: this platform does not support process shared"
                         " mutexes, forcing use of threads. Use the 'thread'"
diff --git a/mutex.c b/mutex.c
index 5e5a0648161de8767bbee98e42ac71d1bef94062..d8c482519909ff334ac5929565908232f541ac24 100644 (file)
--- a/mutex.c
+++ b/mutex.c
@@ -47,7 +47,7 @@ int cond_init_pshared(pthread_cond_t *cond)
                return ret;
        }
 
-#ifdef FIO_HAVE_PSHARED_MUTEX
+#ifdef CONFIG_PSHARED
        ret = pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED);
        if (ret) {
                log_err("pthread_condattr_setpshared: %s\n", strerror(ret));
@@ -77,7 +77,7 @@ int mutex_init_pshared(pthread_mutex_t *mutex)
        /*
         * Not all platforms support process shared mutexes (FreeBSD)
         */
-#ifdef FIO_HAVE_PSHARED_MUTEX
+#ifdef CONFIG_PSHARED
        ret = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
        if (ret) {
                log_err("pthread_mutexattr_setpshared: %s\n", strerror(ret));
@@ -287,7 +287,7 @@ struct fio_rwlock *fio_rwlock_init(void)
                log_err("pthread_rwlockattr_init: %s\n", strerror(ret));
                goto err;
        }
-#ifdef FIO_HAVE_PSHARED_MUTEX
+#ifdef CONFIG_PSHARED
        ret = pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
        if (ret) {
                log_err("pthread_rwlockattr_setpshared: %s\n", strerror(ret));
index bdc190a97734b495852cce7192a9ed2d050054a9..e204d6f27f270f1e63a06809fb4fdaffb2cbe1e4 100644 (file)
@@ -14,8 +14,6 @@
 #define FIO_USE_GENERIC_RAND
 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
 
-#define FIO_HAVE_PSHARED_MUTEX
-
 #define OS_MAP_ANON            MAP_ANON
 #define OS_MSG_DONTWAIT                0
 
index cdae7030e1609d02b7a7acf40377fc84eb11d57c..b59fac159ef47796e2860fccf464845116e074d1 100644 (file)
@@ -27,7 +27,6 @@
 #define FIO_HAVE_ODIRECT
 #define FIO_HAVE_HUGETLB
 #define FIO_HAVE_BLKTRACE
-#define FIO_HAVE_PSHARED_MUTEX
 #define FIO_HAVE_CL_SIZE
 #define FIO_HAVE_FS_STAT
 #define FIO_HAVE_TRIM
index 3d7dbe6573b8a8841e4cdcd0f38db22e8c06448a..c7863b5e02eb5b978f266cc5d9329827c1819aca 100644 (file)
 #define FIO_HAVE_CPU_AFFINITY
 #define FIO_HAVE_SHM_ATTACH_REMOVED
 
-#if _POSIX_THREAD_PROCESS_SHARED > 0
-#define FIO_HAVE_PSHARED_MUTEX
-#endif
-
 #define OS_MAP_ANON            MAP_ANON
 
 #define fio_swap16(x)  bswap16(x)
index 1707ddd8cedcf924abc1de0a26b3345be82b4495..6a240b0d0609f5517284df389ff10d515db0f991 100644 (file)
@@ -22,7 +22,6 @@
 #define FIO_HAVE_ODIRECT
 #define FIO_USE_GENERIC_RAND
 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
-#define FIO_HAVE_PSHARED_MUTEX
 #define FIO_HAVE_CHARDEV_SIZE
 
 #define OS_MAP_ANON            MAP_ANONYMOUS
index 7be833bf067a5f81df3505fb2a74df4af4cdc265..7b328dc090796136152e1d75c29652116f8523a1 100644 (file)
@@ -32,7 +32,6 @@
 #define FIO_HAVE_HUGETLB
 #define FIO_HAVE_RAWBIND
 #define FIO_HAVE_BLKTRACE
-#define FIO_HAVE_PSHARED_MUTEX
 #define FIO_HAVE_CL_SIZE
 #define FIO_HAVE_CGROUPS
 #define FIO_HAVE_FS_STAT
index 73ad84a31e477a9225db23cf480c1d7121d07a63..8f8f53b621c7de8fab15fc738e7591d35d3172fa 100644 (file)
@@ -16,7 +16,6 @@
 #include "../file.h"
 
 #define FIO_HAVE_CPU_AFFINITY
-#define FIO_HAVE_PSHARED_MUTEX
 #define FIO_HAVE_CHARDEV_SIZE
 #define FIO_USE_GENERIC_BDEV_SIZE
 #define FIO_USE_GENERIC_INIT_RANDOM_STATE