]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/fiber/detail/futex.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / fiber / detail / futex.hpp
1
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)
6
7 #ifndef BOOST_FIBERS_DETAIL_FUTEX_H
8 #define BOOST_FIBERS_DETAIL_FUTEX_H
9
10 #include <boost/config.hpp>
11 #include <boost/predef.h>
12
13 #include <boost/fiber/detail/config.hpp>
14
15 #if BOOST_OS_LINUX
16 extern "C" {
17 #include <linux/futex.h>
18 #include <sys/syscall.h>
19 }
20 #elif BOOST_OS_WINDOWS
21 #include <windows.h>
22 #endif
23
24 namespace boost {
25 namespace fibers {
26 namespace detail {
27
28 #if BOOST_OS_LINUX
29 BOOST_FORCEINLINE
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);
32 }
33
34 BOOST_FORCEINLINE
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;
37 }
38
39 BOOST_FORCEINLINE
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;
42 }
43 #elif BOOST_OS_WINDOWS
44 BOOST_FORCEINLINE
45 int futex_wake( std::atomic< std::int32_t > * addr) {
46 ::WakeByAddressSingle( static_cast< void * >( addr) );
47 return 0;
48 }
49
50 BOOST_FORCEINLINE
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);
53 return 0;
54 }
55 #else
56 # warn "no futex support on this platform"
57 #endif
58
59 }}}
60
61 #endif // BOOST_FIBERS_DETAIL_FUTEX_H