From 155f1bf174e2b87a4de721e936f8b6ab141079fb Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Tue, 16 May 2023 12:56:42 +0800 Subject: [PATCH] Use posix compat code for old macOS without libdispatch (#1409) See: https://github.com/AcademySoftwareFoundation/openexr/issues/1405 Signed-off-by: Sergey Fedorov --- src/lib/IlmThread/IlmThreadSemaphore.h | 36 ++++++++++--------- src/lib/IlmThread/IlmThreadSemaphoreOSX.cpp | 5 +++ .../IlmThreadSemaphorePosixCompat.cpp | 11 ++++-- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/lib/IlmThread/IlmThreadSemaphore.h b/src/lib/IlmThread/IlmThreadSemaphore.h index 576968aa65..fc75de3bac 100644 --- a/src/lib/IlmThread/IlmThreadSemaphore.h +++ b/src/lib/IlmThread/IlmThreadSemaphore.h @@ -18,21 +18,25 @@ #include "IlmThreadConfig.h" #include "IlmThreadNamespace.h" +#if defined(__APPLE__) +# include +#endif + #if ILMTHREAD_THREADING_ENABLED -# if ILMTHREAD_HAVE_POSIX_SEMAPHORES -# include -# elif defined(__APPLE__) -# include -# elif (defined (_WIN32) || defined (_WIN64)) -# ifdef NOMINMAX -# undef NOMINMAX -# endif -# define NOMINMAX -# include -# else -# include -# include -# endif +# if ILMTHREAD_HAVE_POSIX_SEMAPHORES +# include +# elif defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED > 1050 && !defined(__ppc__) +# include +# elif (defined(_WIN32) || defined(_WIN64)) +# ifdef NOMINMAX +# undef NOMINMAX +# endif +# define NOMINMAX +# include +# else +# include +# include +# endif #endif ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER @@ -56,8 +60,8 @@ class ILMTHREAD_EXPORT_TYPE Semaphore mutable sem_t _semaphore; -#elif defined(__APPLE__) - mutable dispatch_semaphore_t _semaphore; +#elif defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED > 1050 && !defined(__ppc__) + mutable dispatch_semaphore_t _semaphore; #elif (defined (_WIN32) || defined (_WIN64)) diff --git a/src/lib/IlmThread/IlmThreadSemaphoreOSX.cpp b/src/lib/IlmThread/IlmThreadSemaphoreOSX.cpp index 0ab0b37cf2..3c49578d4b 100644 --- a/src/lib/IlmThread/IlmThreadSemaphoreOSX.cpp +++ b/src/lib/IlmThread/IlmThreadSemaphoreOSX.cpp @@ -11,6 +11,10 @@ //----------------------------------------------------------------------------- #if defined(__APPLE__) && !ILMTHREAD_HAVE_POSIX_SEMAPHORES +# include + +// No libdispatch prior to 10.6, and no support for it on any ppc. +#if __MAC_OS_X_VERSION_MIN_REQUIRED > 1050 && !defined(__ppc__) #include "IlmThreadSemaphore.h" #include "Iex.h" @@ -66,4 +70,5 @@ Semaphore::value () const ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT +# endif #endif diff --git a/src/lib/IlmThread/IlmThreadSemaphorePosixCompat.cpp b/src/lib/IlmThread/IlmThreadSemaphorePosixCompat.cpp index a2d562d636..fda6a5b26f 100644 --- a/src/lib/IlmThread/IlmThreadSemaphorePosixCompat.cpp +++ b/src/lib/IlmThread/IlmThreadSemaphorePosixCompat.cpp @@ -12,10 +12,17 @@ #include "IlmThreadConfig.h" +#if defined(__APPLE__) +# include +#endif + +// Use this code as a fallback for macOS versions without libdispatch. #if ILMTHREAD_THREADING_ENABLED -#if ( !(ILMTHREAD_HAVE_POSIX_SEMAPHORES) && !defined (__APPLE__) && !defined (_WIN32) && !defined (_WIN64) ) +# if (!(ILMTHREAD_HAVE_POSIX_SEMAPHORES) && !defined(_WIN32) && !defined(_WIN64) && \ + (!defined(__APPLE__) || (defined(__APPLE__) && \ + (__MAC_OS_X_VERSION_MIN_REQUIRED < 1060 || defined(__ppc__))))) -#include "IlmThreadSemaphore.h" +# include "IlmThreadSemaphore.h" ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER