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 #ifndef BOOST_ATOMIC_DETAIL_WAIT_OPS_FREEBSD_UMTX_HPP_INCLUDED_
0016 #define BOOST_ATOMIC_DETAIL_WAIT_OPS_FREEBSD_UMTX_HPP_INCLUDED_
0017
0018 #include <sys/types.h>
0019 #include <sys/umtx.h>
0020 #include <cstddef>
0021 #include <boost/memory_order.hpp>
0022 #include <boost/atomic/detail/config.hpp>
0023 #include <boost/atomic/detail/int_sizes.hpp>
0024 #include <boost/atomic/detail/wait_operations_fwd.hpp>
0025 #include <boost/atomic/detail/header.hpp>
0026
0027 #ifdef BOOST_HAS_PRAGMA_ONCE
0028 #pragma once
0029 #endif
0030
0031 namespace boost {
0032 namespace atomics {
0033 namespace detail {
0034
0035 #if defined(UMTX_OP_WAIT_UINT) || defined(UMTX_OP_WAIT)
0036
0037 template< typename Base >
0038 struct wait_operations_freebsd_umtx_common :
0039 public Base
0040 {
0041 typedef Base base_type;
0042 typedef typename base_type::storage_type storage_type;
0043
0044 static BOOST_CONSTEXPR_OR_CONST bool always_has_native_wait_notify = true;
0045
0046 static BOOST_FORCEINLINE bool has_native_wait_notify(storage_type const volatile&) BOOST_NOEXCEPT
0047 {
0048 return true;
0049 }
0050
0051 static BOOST_FORCEINLINE void notify_one(storage_type volatile& storage) BOOST_NOEXCEPT
0052 {
0053 ::_umtx_op(const_cast< storage_type* >(&storage), UMTX_OP_WAKE, 1u, NULL, NULL);
0054 }
0055
0056 static BOOST_FORCEINLINE void notify_all(storage_type volatile& storage) BOOST_NOEXCEPT
0057 {
0058 ::_umtx_op(const_cast< storage_type* >(&storage), UMTX_OP_WAKE, (~static_cast< unsigned int >(0u)) >> 1, NULL, NULL);
0059 }
0060 };
0061
0062 #endif
0063
0064
0065 #if defined(UMTX_OP_WAIT_UINT) && BOOST_ATOMIC_DETAIL_SIZEOF_INT < BOOST_ATOMIC_DETAIL_SIZEOF_LONG
0066
0067 template< typename Base, bool Interprocess >
0068 struct wait_operations< Base, sizeof(unsigned int), true, Interprocess > :
0069 public wait_operations_freebsd_umtx_common< Base >
0070 {
0071 typedef wait_operations_freebsd_umtx_common< Base > base_type;
0072 typedef typename base_type::storage_type storage_type;
0073
0074 static BOOST_FORCEINLINE storage_type wait(storage_type const volatile& storage, storage_type old_val, memory_order order) BOOST_NOEXCEPT
0075 {
0076 storage_type new_val = base_type::load(storage, order);
0077 while (new_val == old_val)
0078 {
0079 ::_umtx_op(const_cast< storage_type* >(&storage), UMTX_OP_WAIT_UINT, old_val, NULL, NULL);
0080 new_val = base_type::load(storage, order);
0081 }
0082
0083 return new_val;
0084 }
0085 };
0086
0087 #endif
0088
0089 #if defined(UMTX_OP_WAIT)
0090
0091 template< typename Base, bool Interprocess >
0092 struct wait_operations< Base, sizeof(unsigned long), true, Interprocess > :
0093 public wait_operations_freebsd_umtx_common< Base >
0094 {
0095 typedef wait_operations_freebsd_umtx_common< Base > base_type;
0096 typedef typename base_type::storage_type storage_type;
0097
0098 static BOOST_FORCEINLINE storage_type wait(storage_type const volatile& storage, storage_type old_val, memory_order order) BOOST_NOEXCEPT
0099 {
0100 storage_type new_val = base_type::load(storage, order);
0101 while (new_val == old_val)
0102 {
0103 ::_umtx_op(const_cast< storage_type* >(&storage), UMTX_OP_WAIT, old_val, NULL, NULL);
0104 new_val = base_type::load(storage, order);
0105 }
0106
0107 return new_val;
0108 }
0109 };
0110
0111 #endif
0112
0113 }
0114 }
0115 }
0116
0117 #include <boost/atomic/detail/footer.hpp>
0118
0119 #endif