Skip to content

Commit

Permalink
Use posix compat code for old macOS without libdispatch (#1409)
Browse files Browse the repository at this point in the history
See: #1405

Signed-off-by: Sergey Fedorov <[email protected]>
  • Loading branch information
barracuda156 authored and kdt3rd committed May 19, 2023
1 parent a941529 commit 155f1bf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
36 changes: 20 additions & 16 deletions src/lib/IlmThread/IlmThreadSemaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,25 @@
#include "IlmThreadConfig.h"
#include "IlmThreadNamespace.h"

#if defined(__APPLE__)
# include <AvailabilityMacros.h>
#endif

#if ILMTHREAD_THREADING_ENABLED
# if ILMTHREAD_HAVE_POSIX_SEMAPHORES
# include <semaphore.h>
# elif defined(__APPLE__)
# include <dispatch/dispatch.h>
# elif (defined (_WIN32) || defined (_WIN64))
# ifdef NOMINMAX
# undef NOMINMAX
# endif
# define NOMINMAX
# include <windows.h>
# else
# include <mutex>
# include <condition_variable>
# endif
# if ILMTHREAD_HAVE_POSIX_SEMAPHORES
# include <semaphore.h>
# elif defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED > 1050 && !defined(__ppc__)
# include <dispatch/dispatch.h>
# elif (defined(_WIN32) || defined(_WIN64))
# ifdef NOMINMAX
# undef NOMINMAX
# endif
# define NOMINMAX
# include <windows.h>
# else
# include <condition_variable>
# include <mutex>
# endif
#endif

ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER
Expand All @@ -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))

Expand Down
5 changes: 5 additions & 0 deletions src/lib/IlmThread/IlmThreadSemaphoreOSX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
//-----------------------------------------------------------------------------

#if defined(__APPLE__) && !ILMTHREAD_HAVE_POSIX_SEMAPHORES
# include <AvailabilityMacros.h>

// 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"
Expand Down Expand Up @@ -66,4 +70,5 @@ Semaphore::value () const

ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT

# endif
#endif
11 changes: 9 additions & 2 deletions src/lib/IlmThread/IlmThreadSemaphorePosixCompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@

#include "IlmThreadConfig.h"

#if defined(__APPLE__)
# include <AvailabilityMacros.h>
#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

Expand Down

0 comments on commit 155f1bf

Please sign in to comment.