Chris@102: /* Chris@102: * Distributed under the Boost Software License, Version 1.0. Chris@102: * (See accompanying file LICENSE_1_0.txt or copy at Chris@102: * http://www.boost.org/LICENSE_1_0.txt) Chris@102: * Chris@102: * Copyright (c) 2014 Andrey Semashev Chris@102: */ Chris@102: /*! Chris@102: * \file atomic/detail/atomic_flag.hpp Chris@102: * Chris@102: * This header contains interface definition of \c atomic_flag. Chris@102: */ Chris@102: Chris@102: #ifndef BOOST_ATOMIC_DETAIL_ATOMIC_FLAG_HPP_INCLUDED_ Chris@102: #define BOOST_ATOMIC_DETAIL_ATOMIC_FLAG_HPP_INCLUDED_ Chris@102: Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: Chris@102: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@102: #pragma once Chris@102: #endif Chris@102: Chris@102: /* Chris@102: * IMPLEMENTATION NOTE: All interface functions MUST be declared with BOOST_FORCEINLINE, Chris@102: * see comment for convert_memory_order_to_gcc in ops_gcc_atomic.hpp. Chris@102: */ Chris@102: Chris@102: namespace boost { Chris@102: namespace atomics { Chris@102: Chris@102: #if defined(BOOST_NO_CXX11_CONSTEXPR) || defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) Chris@102: #define BOOST_ATOMIC_NO_ATOMIC_FLAG_INIT Chris@102: #else Chris@102: #define BOOST_ATOMIC_FLAG_INIT {} Chris@102: #endif Chris@102: Chris@102: struct atomic_flag Chris@102: { Chris@102: typedef atomics::detail::operations< 1u, false > operations; Chris@102: typedef operations::storage_type storage_type; Chris@102: Chris@102: storage_type m_storage; Chris@102: Chris@102: BOOST_FORCEINLINE BOOST_CONSTEXPR atomic_flag() BOOST_NOEXCEPT : m_storage(0) Chris@102: { Chris@102: } Chris@102: Chris@102: BOOST_FORCEINLINE bool test_and_set(memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT Chris@102: { Chris@102: return operations::test_and_set(m_storage, order); Chris@102: } Chris@102: Chris@102: BOOST_FORCEINLINE void clear(memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT Chris@102: { Chris@102: BOOST_ASSERT(order != memory_order_acquire); Chris@102: BOOST_ASSERT(order != memory_order_acq_rel); Chris@102: operations::clear(m_storage, order); Chris@102: } Chris@102: Chris@102: BOOST_DELETED_FUNCTION(atomic_flag(atomic_flag const&)) Chris@102: BOOST_DELETED_FUNCTION(atomic_flag& operator= (atomic_flag const&)) Chris@102: }; Chris@102: Chris@102: } // namespace atomics Chris@102: } // namespace boost Chris@102: Chris@102: #endif // BOOST_ATOMIC_DETAIL_ATOMIC_FLAG_HPP_INCLUDED_