]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/atomic/atomic_ref.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / atomic / atomic_ref.hpp
CommitLineData
f67539c2
TL
1/*
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
5 *
1e59de90 6 * Copyright (c) 2020-2021 Andrey Semashev
f67539c2
TL
7 */
8/*!
9 * \file atomic/atomic_ref.hpp
10 *
11 * This header contains definition of \c atomic_ref template.
12 */
13
14#ifndef BOOST_ATOMIC_ATOMIC_REF_HPP_INCLUDED_
15#define BOOST_ATOMIC_ATOMIC_REF_HPP_INCLUDED_
16
20effc67
TL
17#include <boost/assert.hpp>
18#include <boost/static_assert.hpp>
19#include <boost/memory_order.hpp>
f67539c2 20#include <boost/atomic/capabilities.hpp>
20effc67
TL
21#include <boost/atomic/detail/config.hpp>
22#include <boost/atomic/detail/intptr.hpp>
23#include <boost/atomic/detail/classify.hpp>
24#include <boost/atomic/detail/atomic_ref_impl.hpp>
25#include <boost/atomic/detail/type_traits/is_trivially_copyable.hpp>
26#include <boost/atomic/detail/header.hpp>
f67539c2
TL
27
28#ifdef BOOST_HAS_PRAGMA_ONCE
29#pragma once
30#endif
31
32namespace boost {
20effc67
TL
33namespace atomics {
34
35//! Atomic reference to external object
36template< typename T >
37class atomic_ref :
38 public atomics::detail::base_atomic_ref< T, typename atomics::detail::classify< T >::type, false >
39{
40private:
41 typedef atomics::detail::base_atomic_ref< T, typename atomics::detail::classify< T >::type, false > base_type;
42 typedef typename base_type::value_arg_type value_arg_type;
43
44public:
45 typedef typename base_type::value_type value_type;
46
47 BOOST_STATIC_ASSERT_MSG(sizeof(value_type) > 0u, "boost::atomic_ref<T> requires T to be a complete type");
48#if !defined(BOOST_ATOMIC_DETAIL_NO_CXX11_IS_TRIVIALLY_COPYABLE)
49 BOOST_STATIC_ASSERT_MSG(atomics::detail::is_trivially_copyable< value_type >::value, "boost::atomic_ref<T> requires T to be a trivially copyable type");
50#endif
51
52private:
53 typedef typename base_type::storage_type storage_type;
54
55public:
56 BOOST_DEFAULTED_FUNCTION(atomic_ref(atomic_ref const& that) BOOST_ATOMIC_DETAIL_DEF_NOEXCEPT_DECL, BOOST_ATOMIC_DETAIL_DEF_NOEXCEPT_IMPL : base_type(static_cast< base_type const& >(that)) {})
57 BOOST_FORCEINLINE explicit atomic_ref(value_type& v) BOOST_NOEXCEPT : base_type(v)
58 {
59 // Check that referenced object alignment satisfies required alignment
60 BOOST_ASSERT((((atomics::detail::uintptr_t)this->m_value) & (base_type::required_alignment - 1u)) == 0u);
61 }
62
63 BOOST_FORCEINLINE value_type operator= (value_arg_type v) const BOOST_NOEXCEPT
64 {
65 this->store(v);
66 return v;
67 }
68
69 BOOST_FORCEINLINE operator value_type() const BOOST_NOEXCEPT
70 {
71 return this->load();
72 }
73
74 BOOST_DELETED_FUNCTION(atomic_ref& operator= (atomic_ref const&))
75};
76
1e59de90
TL
77#if !defined(BOOST_ATOMIC_DETAIL_NO_CXX17_DEDUCTION_GUIDES)
78template< typename T >
79atomic_ref(T&) -> atomic_ref< T >;
80#endif // !defined(BOOST_ATOMIC_DETAIL_NO_CXX17_DEDUCTION_GUIDES)
81
82//! Atomic reference factory function
83template< typename T >
84BOOST_FORCEINLINE atomic_ref< T > make_atomic_ref(T& value) BOOST_NOEXCEPT
85{
86 return atomic_ref< T >(value);
87}
88
20effc67 89} // namespace atomics
f67539c2
TL
90
91using atomics::atomic_ref;
1e59de90 92using atomics::make_atomic_ref;
f67539c2
TL
93
94} // namespace boost
95
20effc67
TL
96#include <boost/atomic/detail/footer.hpp>
97
f67539c2 98#endif // BOOST_ATOMIC_ATOMIC_REF_HPP_INCLUDED_