From 58f26c32210716e0f12a0189bfb891e0ca62114f Mon Sep 17 00:00:00 2001 From: Oleh Derevenko Date: Mon, 17 Dec 2018 02:29:18 +0200 Subject: [PATCH] Changed: Conditional defines handling was improved to allow the built-in threading implementation to be compiled for POSIX targets even if autoconf was not run --- configure.ac | 6 ++++++ ode/src/threading_impl_posix.h | 35 ++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index 7180bb10..7a615439 100644 --- a/configure.ac +++ b/configure.ac @@ -288,6 +288,12 @@ AC_CHECK_LIB(rt, [main]) AC_CHECK_FUNCS([atan2f clock_gettime copysign copysignf cosf fabsf floor fmodf gettimeofday isnan _isnan __isnan isnanf _isnanf __isnanf memmove memset pthread_attr_setstacklazy pthread_condattr_setclock sinf snprintf sqrt sqrtf strchr strstr vsnprintf]) AC_FUNC_ALLOCA +dnl This trick allows having additional define in case if a function is not found. +dnl It fakes cached value for an inexistent function which is then used to fool function check to produce desired result. +AC_CHECK_FUNC(pthread_condattr_setclock,,ac_cv_func_no_pthread_condattr_setclock=yes) +AC_CHECK_FUNCS(no_pthread_condattr_setclock) + + AC_ARG_ENABLE([threading-intf], AS_HELP_STRING([--disable-threading-intf], [disable threading interface support (external implementations cannot be assigned)] diff --git a/ode/src/threading_impl_posix.h b/ode/src/threading_impl_posix.h index 2538b930..0a6c8bfa 100644 --- a/ode/src/threading_impl_posix.h +++ b/ode/src/threading_impl_posix.h @@ -55,17 +55,6 @@ #endif -#if HAVE_PTHREAD_CONDATTR_SETCLOCK - -static inline -int _condvar_clock_gettime(int clock_type, timespec *ts) -{ - return clock_gettime(clock_type, ts); -} - - -#else // #if !HAVE_PTHREAD_CONDATTR_SETCLOCK - #if defined(__APPLE__) #if HAVE_GETTIMEOFDAY @@ -95,16 +84,36 @@ int _condvar_clock_gettime(int clock_type, timespec *ts) #else // #if !defined(__APPLE__) +#if !HAVE_PTHREAD_CONDATTR_SETCLOCK && !HAVE_NO_PTHREAD_CONDATTR_SETCLOCK -#error It is necessary to check manuals for the correct way of getting condvar wait time for this system +// The code must be compiled without autoconf run, having the project generated by other means. +// Assume the pthread_condattr_setclock() is available as it is true in most cases and it is the best we can do in such cases. +#define HAVE_PTHREAD_CONDATTR_SETCLOCK 1 -#endif // #if !defined(__APPLE__) +#endif // #if !HAVE_PTHREAD_CONDATTR_SETCLOCK && !HAVE_NO_PTHREAD_CONDATTR_SETCLOCK + + +#if HAVE_PTHREAD_CONDATTR_SETCLOCK + +static inline +int _condvar_clock_gettime(int clock_type, timespec *ts) +{ + return clock_gettime(clock_type, ts); +} + + +#else // #if !HAVE_PTHREAD_CONDATTR_SETCLOCK + +#error It is necessary to check manuals for the correct way of getting condvar wait time for this system #endif // #if !HAVE_PTHREAD_CONDATTR_SETCLOCK +#endif // #if !defined(__APPLE__) + + /************************************************************************/ /* dxCondvarWakeup class implementation */ /************************************************************************/ -- 2.11.4.GIT