File indexing completed on 2025-01-30 09:33:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef BOOST_ATOMIC_DETAIL_WAIT_OPS_DARWIN_ULOCK_HPP_INCLUDED_
0018 #define BOOST_ATOMIC_DETAIL_WAIT_OPS_DARWIN_ULOCK_HPP_INCLUDED_
0019
0020 #include <stdint.h>
0021 #include <cerrno>
0022 #include <boost/memory_order.hpp>
0023 #include <boost/atomic/detail/config.hpp>
0024 #include <boost/atomic/detail/wait_capabilities.hpp>
0025 #include <boost/atomic/detail/wait_operations_fwd.hpp>
0026 #include <boost/atomic/detail/header.hpp>
0027
0028 #ifdef BOOST_HAS_PRAGMA_ONCE
0029 #pragma once
0030 #endif
0031
0032 namespace boost {
0033 namespace atomics {
0034 namespace detail {
0035
0036 extern "C" {
0037
0038 int __ulock_wait(uint32_t operation, void* addr, uint64_t value, uint32_t timeout);
0039 #if defined(BOOST_ATOMIC_DETAIL_HAS_DARWIN_ULOCK_WAIT2)
0040
0041 int __ulock_wait2(uint32_t operation, void* addr, uint64_t value, uint64_t timeout, uint64_t value2);
0042 #endif
0043 int __ulock_wake(uint32_t operation, void* addr, uint64_t wake_value);
0044 }
0045
0046 enum ulock_op
0047 {
0048 ulock_op_compare_and_wait = 1,
0049 #if defined(BOOST_ATOMIC_DETAIL_HAS_DARWIN_ULOCK_SHARED)
0050 ulock_op_compare_and_wait_shared = 3,
0051 #endif
0052 #if defined(BOOST_ATOMIC_DETAIL_HAS_DARWIN_ULOCK64)
0053 ulock_op_compare_and_wait64 = 5,
0054 #if defined(BOOST_ATOMIC_DETAIL_HAS_DARWIN_ULOCK_SHARED)
0055 ulock_op_compare_and_wait64_shared = 6,
0056 #endif
0057 #endif
0058
0059
0060 ulock_flag_wake_all = 0x00000100,
0061
0062
0063 ulock_flag_no_errno = 0x01000000
0064 };
0065
0066 template< typename Base, uint32_t Opcode >
0067 struct wait_operations_darwin_ulock_common :
0068 public Base
0069 {
0070 typedef Base base_type;
0071 typedef typename base_type::storage_type storage_type;
0072
0073 static BOOST_CONSTEXPR_OR_CONST bool always_has_native_wait_notify = true;
0074
0075 static BOOST_FORCEINLINE bool has_native_wait_notify(storage_type const volatile&) BOOST_NOEXCEPT
0076 {
0077 return true;
0078 }
0079
0080 static BOOST_FORCEINLINE storage_type wait(storage_type const volatile& storage, storage_type old_val, memory_order order) BOOST_NOEXCEPT
0081 {
0082 storage_type new_val = base_type::load(storage, order);
0083 while (new_val == old_val)
0084 {
0085 #if defined(BOOST_ATOMIC_DETAIL_HAS_DARWIN_ULOCK_WAIT2)
0086 __ulock_wait2(Opcode | ulock_flag_no_errno, const_cast< storage_type* >(&storage), old_val, 0u, 0u);
0087 #else
0088 __ulock_wait(Opcode | ulock_flag_no_errno, const_cast< storage_type* >(&storage), old_val, 0u);
0089 #endif
0090 new_val = base_type::load(storage, order);
0091 }
0092
0093 return new_val;
0094 }
0095
0096 static BOOST_FORCEINLINE void notify_one(storage_type volatile& storage) BOOST_NOEXCEPT
0097 {
0098 while (true)
0099 {
0100 const int res = __ulock_wake(Opcode | ulock_flag_no_errno, const_cast< storage_type* >(&storage), 0u);
0101 if (BOOST_LIKELY(res != -EINTR))
0102 break;
0103 }
0104 }
0105
0106 static BOOST_FORCEINLINE void notify_all(storage_type volatile& storage) BOOST_NOEXCEPT
0107 {
0108 while (true)
0109 {
0110 const int res = __ulock_wake(Opcode | ulock_flag_wake_all | ulock_flag_no_errno, const_cast< storage_type* >(&storage), 0u);
0111 if (BOOST_LIKELY(res != -EINTR))
0112 break;
0113 }
0114 }
0115 };
0116
0117 template< typename Base >
0118 struct wait_operations< Base, sizeof(uint32_t), true, false > :
0119 public wait_operations_darwin_ulock_common< Base, ulock_op_compare_and_wait >
0120 {
0121 };
0122
0123 #if defined(BOOST_ATOMIC_DETAIL_HAS_DARWIN_ULOCK_SHARED)
0124
0125 template< typename Base >
0126 struct wait_operations< Base, sizeof(uint32_t), true, true > :
0127 public wait_operations_darwin_ulock_common< Base, ulock_op_compare_and_wait_shared >
0128 {
0129 };
0130
0131 #endif
0132
0133 #if defined(BOOST_ATOMIC_DETAIL_HAS_DARWIN_ULOCK64)
0134
0135 template< typename Base >
0136 struct wait_operations< Base, sizeof(uint64_t), true, false > :
0137 public wait_operations_darwin_ulock_common< Base, ulock_op_compare_and_wait64 >
0138 {
0139 };
0140
0141 #if defined(BOOST_ATOMIC_DETAIL_HAS_DARWIN_ULOCK_SHARED)
0142
0143 template< typename Base >
0144 struct wait_operations< Base, sizeof(uint64_t), true, true > :
0145 public wait_operations_darwin_ulock_common< Base, ulock_op_compare_and_wait64_shared >
0146 {
0147 };
0148
0149 #endif
0150 #endif
0151
0152 }
0153 }
0154 }
0155
0156 #include <boost/atomic/detail/footer.hpp>
0157
0158 #endif