Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:35:34

0001 
0002 //          Copyright Oliver Kowalke 2016.
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //    (See accompanying file LICENSE_1_0.txt or copy at
0005 //          http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef BOOST_FIBERS_DETAIL_FUTEX_H
0008 #define BOOST_FIBERS_DETAIL_FUTEX_H
0009 
0010 #include <boost/config.hpp>
0011 #include <boost/predef.h> 
0012 
0013 #include <boost/fiber/detail/config.hpp>
0014 
0015 #ifndef SYS_futex
0016 #define SYS_futex SYS_futex_time64
0017 #endif
0018 
0019 #if BOOST_OS_LINUX
0020 extern "C" {
0021 #include <linux/futex.h>
0022 #include <sys/syscall.h>
0023 }
0024 #elif BOOST_OS_WINDOWS
0025 #include <windows.h>
0026 #endif
0027 
0028 namespace boost {
0029 namespace fibers {
0030 namespace detail {
0031 
0032 #if BOOST_OS_LINUX
0033 BOOST_FORCEINLINE
0034 int sys_futex( void * addr, std::int32_t op, std::int32_t x) {
0035     return ::syscall( SYS_futex, addr, op, x, nullptr, nullptr, 0);
0036 }
0037 
0038 BOOST_FORCEINLINE
0039 int futex_wake( std::atomic< std::int32_t > * addr) {
0040     return 0 <= sys_futex( static_cast< void * >( addr), FUTEX_WAKE_PRIVATE, 1) ? 0 : -1;
0041 }
0042 
0043 BOOST_FORCEINLINE
0044 int futex_wait( std::atomic< std::int32_t > * addr, std::int32_t x) {
0045     return 0 <= sys_futex( static_cast< void * >( addr), FUTEX_WAIT_PRIVATE, x) ? 0 : -1;
0046 }
0047 #elif BOOST_OS_WINDOWS
0048 BOOST_FORCEINLINE
0049 int futex_wake( std::atomic< std::int32_t > * addr) {
0050     ::WakeByAddressSingle( static_cast< void * >( addr) );
0051     return 0;
0052 }
0053 
0054 BOOST_FORCEINLINE
0055 int futex_wait( std::atomic< std::int32_t > * addr, std::int32_t x) {
0056     ::WaitOnAddress( static_cast< volatile void * >( addr), & x, sizeof( x), INFINITE);
0057     return 0;
0058 }
0059 #else
0060 # warn "no futex support on this platform"
0061 #endif
0062 
0063 }}}
0064 
0065 #endif // BOOST_FIBERS_DETAIL_FUTEX_H