Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions include/boost/fiber/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@
#include <cstddef>

#include <boost/config.hpp>
#include <boost/predef.h>
#include <boost/predef.h>
#include <boost/detail/workaround.hpp>

#if BOOST_OS_MACOS
#include <Availability.h>
#define BOOST_OS_SYNC_WAIT_ON_ADDRESS_AVAILABLE \
__MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_14_4
#endif

#ifdef BOOST_FIBERS_DECL
# undef BOOST_FIBERS_DECL
#endif
Expand All @@ -38,7 +44,8 @@
# include <boost/config/auto_link.hpp>
#endif

#if BOOST_OS_LINUX || BOOST_OS_BSD_OPEN || BOOST_OS_WINDOWS
#if BOOST_OS_LINUX || BOOST_OS_BSD_OPEN || BOOST_OS_WINDOWS || (BOOST_OS_MACOS && \
BOOST_OS_SYNC_WAIT_ON_ADDRESS_AVAILABLE)
# define BOOST_FIBERS_HAS_FUTEX
#endif

Expand Down
15 changes: 14 additions & 1 deletion include/boost/fiber/detail/futex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define BOOST_FIBERS_DETAIL_FUTEX_H

#include <boost/config.hpp>
#include <boost/predef.h>
#include <boost/predef.h>

#include <boost/fiber/detail/config.hpp>

Expand All @@ -27,6 +27,8 @@ extern "C" {
}
#elif BOOST_OS_WINDOWS
#include <windows.h>
#elif (BOOST_OS_MACOS && BOOST_OS_SYNC_WAIT_ON_ADDRESS_AVAILABLE)
#include <os/os_sync_wait_on_address.h>
#endif

namespace boost {
Expand Down Expand Up @@ -71,6 +73,17 @@ int futex_wait( std::atomic< std::int32_t > * addr, std::int32_t x) {
::WaitOnAddress( static_cast< volatile void * >( addr), & x, sizeof( x), INFINITE);
return 0;
}
#elif (BOOST_OS_MACOS && BOOST_OS_SYNC_WAIT_ON_ADDRESS_AVAILABLE)
BOOST_FORCEINLINE
int futex_wake( std::atomic< std::int32_t > * addr) {
return 0 <= os_sync_wake_by_address_any(addr, 4, OS_SYNC_WAKE_BY_ADDRESS_NONE) ? 0 : -1;
}

BOOST_FORCEINLINE
int futex_wait( std::atomic< std::int32_t > * addr, std::int32_t x) {
return 0 <= os_sync_wait_on_address(static_cast< void * >( addr), x, sizeof(x),
OS_SYNC_WAIT_ON_ADDRESS_NONE) ? 0 : -1;
}
#else
# warn "no futex support on this platform"
#endif
Expand Down