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 May 16, 2023
1 parent b7446c0 commit 7862c23
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/lib/IlmThread/IlmThreadSemaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
#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__)
# elif defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED > 1050 && !defined(__ppc__)
# include <dispatch/dispatch.h>
# elif (defined(_WIN32) || defined(_WIN64))
# ifdef NOMINMAX
Expand Down Expand Up @@ -53,7 +57,7 @@ class ILMTHREAD_EXPORT_TYPE Semaphore

mutable sem_t _semaphore;

#elif defined(__APPLE__)
#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 "Iex.h"
# include "IlmThreadSemaphore.h"
Expand Down Expand Up @@ -59,4 +63,5 @@ Semaphore::value () const

ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT

# endif
#endif
13 changes: 9 additions & 4 deletions src/lib/IlmThread/IlmThreadSemaphorePosixCompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +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 7862c23

Please sign in to comment.