]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/atomic/detail/atomic_flag.hpp
buildsys: switch source download to quincy
[ceph.git] / ceph / src / boost / boost / atomic / detail / atomic_flag.hpp
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 *
6 * Copyright (c) 2014 Andrey Semashev
7 */
8 /*!
9 * \file atomic/detail/atomic_flag.hpp
10 *
11 * This header contains interface definition of \c atomic_flag.
12 */
13
14 #ifndef BOOST_ATOMIC_DETAIL_ATOMIC_FLAG_HPP_INCLUDED_
15 #define BOOST_ATOMIC_DETAIL_ATOMIC_FLAG_HPP_INCLUDED_
16
17 #include <boost/assert.hpp>
18 #include <boost/memory_order.hpp>
19 #include <boost/atomic/detail/config.hpp>
20 #include <boost/atomic/detail/operations.hpp>
21 #if defined(BOOST_ATOMIC_DETAIL_NO_CXX11_ALIGNAS)
22 #include <boost/type_traits/type_with_alignment.hpp>
23 #endif
24
25 #ifdef BOOST_HAS_PRAGMA_ONCE
26 #pragma once
27 #endif
28
29 /*
30 * IMPLEMENTATION NOTE: All interface functions MUST be declared with BOOST_FORCEINLINE,
31 * see comment for convert_memory_order_to_gcc in ops_gcc_atomic.hpp.
32 */
33
34 namespace boost {
35 namespace atomics {
36
37 #if defined(BOOST_ATOMIC_DETAIL_NO_CXX11_CONSTEXPR_UNION_INIT) || defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
38 #define BOOST_ATOMIC_NO_ATOMIC_FLAG_INIT
39 #else
40 #define BOOST_ATOMIC_FLAG_INIT {}
41 #endif
42
43 struct atomic_flag
44 {
45 typedef atomics::detail::operations< 1u, false > operations;
46 typedef operations::storage_type storage_type;
47
48 #if !defined(BOOST_ATOMIC_DETAIL_NO_CXX11_ALIGNAS)
49 alignas(operations::storage_alignment) storage_type m_storage;
50 #else
51 // Note: Some compilers cannot use constant expressions in alignment attributes, so we have to use the union trick
52 union
53 {
54 storage_type m_storage;
55 boost::type_with_alignment< operations::storage_alignment >::type m_aligner;
56 };
57 #endif
58
59 BOOST_FORCEINLINE BOOST_ATOMIC_DETAIL_CONSTEXPR_UNION_INIT atomic_flag() BOOST_NOEXCEPT : m_storage(0u)
60 {
61 }
62
63 BOOST_FORCEINLINE bool test(memory_order order = memory_order_seq_cst) const volatile BOOST_NOEXCEPT
64 {
65 BOOST_ASSERT(order != memory_order_release);
66 BOOST_ASSERT(order != memory_order_acq_rel);
67 return !!operations::load(m_storage, order);
68 }
69
70 BOOST_FORCEINLINE bool test_and_set(memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
71 {
72 return operations::test_and_set(m_storage, order);
73 }
74
75 BOOST_FORCEINLINE void clear(memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
76 {
77 BOOST_ASSERT(order != memory_order_consume);
78 BOOST_ASSERT(order != memory_order_acquire);
79 BOOST_ASSERT(order != memory_order_acq_rel);
80 operations::clear(m_storage, order);
81 }
82
83 BOOST_DELETED_FUNCTION(atomic_flag(atomic_flag const&))
84 BOOST_DELETED_FUNCTION(atomic_flag& operator= (atomic_flag const&))
85 };
86
87 } // namespace atomics
88 } // namespace boost
89
90 #endif // BOOST_ATOMIC_DETAIL_ATOMIC_FLAG_HPP_INCLUDED_