2 // Copyright Oliver Kowalke 2016.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 #ifndef BOOST_FIBERS_DETAIL_FUTEX_H
8 #define BOOST_FIBERS_DETAIL_FUTEX_H
10 #include <boost/config.hpp>
11 #include <boost/predef.h>
13 #include <boost/fiber/detail/config.hpp>
17 #include <linux/futex.h>
18 #include <sys/syscall.h>
20 #elif BOOST_OS_WINDOWS
30 int sys_futex( void * addr, std::int32_t op, std::int32_t x) {
31 return ::syscall( SYS_futex, addr, op, x, nullptr, nullptr, 0);
35 int futex_wake( std::atomic< std::int32_t > * addr) {
36 return 0 <= sys_futex( static_cast< void * >( addr), FUTEX_WAKE_PRIVATE, 1) ? 0 : -1;
40 int futex_wait( std::atomic< std::int32_t > * addr, std::int32_t x) {
41 return 0 <= sys_futex( static_cast< void * >( addr), FUTEX_WAIT_PRIVATE, x) ? 0 : -1;
43 #elif BOOST_OS_WINDOWS
45 int futex_wake( std::atomic< std::int32_t > * addr) {
46 ::WakeByAddressSingle( static_cast< void * >( addr) );
51 int futex_wait( std::atomic< std::int32_t > * addr, std::int32_t x) {
52 ::WaitOnAddress( static_cast< volatile void * >( addr), & x, sizeof( x), INFINITE);
56 # warn "no futex support on this platform"
61 #endif // BOOST_FIBERS_DETAIL_FUTEX_H