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)
6 * Copyright (c) 2014 Andrey Semashev
9 * \file atomic/detail/atomic_flag.hpp
11 * This header contains interface definition of \c atomic_flag.
14 #ifndef BOOST_ATOMIC_DETAIL_ATOMIC_FLAG_HPP_INCLUDED_
15 #define BOOST_ATOMIC_DETAIL_ATOMIC_FLAG_HPP_INCLUDED_
17 #include <boost/assert.hpp>
18 #include <boost/memory_order.hpp>
19 #include <boost/atomic/detail/config.hpp>
20 #include <boost/atomic/detail/operations_lockfree.hpp>
22 #ifdef BOOST_HAS_PRAGMA_ONCE
27 * IMPLEMENTATION NOTE: All interface functions MUST be declared with BOOST_FORCEINLINE,
28 * see comment for convert_memory_order_to_gcc in ops_gcc_atomic.hpp.
34 #if defined(BOOST_NO_CXX11_CONSTEXPR) || defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
35 #define BOOST_ATOMIC_NO_ATOMIC_FLAG_INIT
37 #define BOOST_ATOMIC_FLAG_INIT {}
42 typedef atomics::detail::operations< 1u, false > operations;
43 typedef operations::storage_type storage_type;
45 operations::aligned_storage_type m_storage;
47 BOOST_FORCEINLINE BOOST_CONSTEXPR atomic_flag() BOOST_NOEXCEPT : m_storage(0)
51 BOOST_FORCEINLINE bool test_and_set(memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
53 return operations::test_and_set(m_storage.value, order);
56 BOOST_FORCEINLINE void clear(memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
58 BOOST_ASSERT(order != memory_order_acquire);
59 BOOST_ASSERT(order != memory_order_acq_rel);
60 operations::clear(m_storage.value, order);
63 BOOST_DELETED_FUNCTION(atomic_flag(atomic_flag const&))
64 BOOST_DELETED_FUNCTION(atomic_flag& operator= (atomic_flag const&))
67 } // namespace atomics
70 #endif // BOOST_ATOMIC_DETAIL_ATOMIC_FLAG_HPP_INCLUDED_