File indexing completed on 2025-01-30 09:33:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef BOOST_ATOMIC_DETAIL_WAIT_OPS_WINDOWS_HPP_INCLUDED_
0015 #define BOOST_ATOMIC_DETAIL_WAIT_OPS_WINDOWS_HPP_INCLUDED_
0016
0017 #include <boost/atomic/detail/config.hpp>
0018 #include <boost/memory_order.hpp>
0019 #include <boost/winapi/wait_constants.hpp>
0020 #include <boost/atomic/detail/wait_operations_fwd.hpp>
0021 #include <boost/atomic/detail/wait_capabilities.hpp>
0022 #if defined(BOOST_ATOMIC_DETAIL_WINDOWS_HAS_WAIT_ON_ADDRESS)
0023 #include <boost/winapi/wait_on_address.hpp>
0024 #if (defined(BOOST_ATOMIC_FORCE_AUTO_LINK) || (!defined(BOOST_ALL_NO_LIB) && !defined(BOOST_ATOMIC_NO_LIB))) && !defined(BOOST_ATOMIC_NO_SYNCHRONIZATION_LIB)
0025 #define BOOST_LIB_NAME "synchronization"
0026 #if defined(BOOST_AUTO_LINK_NOMANGLE)
0027 #include <boost/config/auto_link.hpp>
0028 #else
0029 #define BOOST_AUTO_LINK_NOMANGLE
0030 #include <boost/config/auto_link.hpp>
0031 #undef BOOST_AUTO_LINK_NOMANGLE
0032 #endif
0033 #endif
0034 #else
0035 #include <cstddef>
0036 #include <boost/atomic/detail/wait_on_address.hpp>
0037 #include <boost/atomic/detail/wait_ops_generic.hpp>
0038 #endif
0039 #include <boost/atomic/detail/header.hpp>
0040
0041 #ifdef BOOST_HAS_PRAGMA_ONCE
0042 #pragma once
0043 #endif
0044
0045 namespace boost {
0046 namespace atomics {
0047 namespace detail {
0048
0049 #if defined(BOOST_ATOMIC_DETAIL_WINDOWS_HAS_WAIT_ON_ADDRESS)
0050
0051 template< typename Base, std::size_t Size >
0052 struct wait_operations_windows :
0053 public Base
0054 {
0055 typedef Base base_type;
0056 typedef typename base_type::storage_type storage_type;
0057
0058 static BOOST_CONSTEXPR_OR_CONST bool always_has_native_wait_notify = true;
0059
0060 static BOOST_FORCEINLINE bool has_native_wait_notify(storage_type const volatile&) BOOST_NOEXCEPT
0061 {
0062 return true;
0063 }
0064
0065 static BOOST_FORCEINLINE storage_type wait(storage_type const volatile& storage, storage_type old_val, memory_order order) BOOST_NOEXCEPT
0066 {
0067 storage_type new_val = base_type::load(storage, order);
0068 while (new_val == old_val)
0069 {
0070 boost::winapi::WaitOnAddress(const_cast< storage_type* >(&storage), &old_val, Size, boost::winapi::infinite);
0071 new_val = base_type::load(storage, order);
0072 }
0073
0074 return new_val;
0075 }
0076
0077 static BOOST_FORCEINLINE void notify_one(storage_type volatile& storage) BOOST_NOEXCEPT
0078 {
0079 boost::winapi::WakeByAddressSingle(const_cast< storage_type* >(&storage));
0080 }
0081
0082 static BOOST_FORCEINLINE void notify_all(storage_type volatile& storage) BOOST_NOEXCEPT
0083 {
0084 boost::winapi::WakeByAddressAll(const_cast< storage_type* >(&storage));
0085 }
0086 };
0087
0088 #else
0089
0090 template< typename Base, std::size_t Size >
0091 struct wait_operations_windows :
0092 public atomics::detail::wait_operations_generic< Base, false >
0093 {
0094 typedef atomics::detail::wait_operations_generic< Base, false > base_type;
0095 typedef typename base_type::storage_type storage_type;
0096
0097 static BOOST_CONSTEXPR_OR_CONST bool always_has_native_wait_notify = false;
0098
0099 static BOOST_FORCEINLINE bool has_native_wait_notify(storage_type const volatile&) BOOST_NOEXCEPT
0100 {
0101 ensure_wait_functions_initialized();
0102 return atomics::detail::wait_on_address != NULL;
0103 }
0104
0105 static BOOST_FORCEINLINE storage_type wait(storage_type const volatile& storage, storage_type old_val, memory_order order) BOOST_NOEXCEPT
0106 {
0107 ensure_wait_functions_initialized();
0108
0109 if (BOOST_LIKELY(atomics::detail::wait_on_address != NULL))
0110 {
0111 storage_type new_val = base_type::load(storage, order);
0112 while (new_val == old_val)
0113 {
0114 atomics::detail::wait_on_address(const_cast< storage_type* >(&storage), &old_val, Size, boost::winapi::infinite);
0115 new_val = base_type::load(storage, order);
0116 }
0117
0118 return new_val;
0119 }
0120 else
0121 {
0122 return base_type::wait(storage, old_val, order);
0123 }
0124 }
0125
0126 static BOOST_FORCEINLINE void notify_one(storage_type volatile& storage) BOOST_NOEXCEPT
0127 {
0128 ensure_wait_functions_initialized();
0129
0130 if (BOOST_LIKELY(atomics::detail::wake_by_address_single != NULL))
0131 atomics::detail::wake_by_address_single(const_cast< storage_type* >(&storage));
0132 else
0133 base_type::notify_one(storage);
0134 }
0135
0136 static BOOST_FORCEINLINE void notify_all(storage_type volatile& storage) BOOST_NOEXCEPT
0137 {
0138 ensure_wait_functions_initialized();
0139
0140 if (BOOST_LIKELY(atomics::detail::wake_by_address_all != NULL))
0141 atomics::detail::wake_by_address_all(const_cast< storage_type* >(&storage));
0142 else
0143 base_type::notify_all(storage);
0144 }
0145 };
0146
0147 #endif
0148
0149 template< typename Base >
0150 struct wait_operations< Base, 1u, true, false > :
0151 public wait_operations_windows< Base, 1u >
0152 {
0153 };
0154
0155 template< typename Base >
0156 struct wait_operations< Base, 2u, true, false > :
0157 public wait_operations_windows< Base, 2u >
0158 {
0159 };
0160
0161 template< typename Base >
0162 struct wait_operations< Base, 4u, true, false > :
0163 public wait_operations_windows< Base, 4u >
0164 {
0165 };
0166
0167 template< typename Base >
0168 struct wait_operations< Base, 8u, true, false > :
0169 public wait_operations_windows< Base, 8u >
0170 {
0171 };
0172
0173 }
0174 }
0175 }
0176
0177 #include <boost/atomic/detail/footer.hpp>
0178
0179 #endif