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) 2020 Andrey Semashev 7 */ 8 /*! 9 * \file atomic/ipc_atomic.hpp 10 * 11 * This header contains definition of \c ipc_atomic template. 12 */ 13 14 #ifndef BOOST_ATOMIC_IPC_ATOMIC_HPP_INCLUDED_ 15 #define BOOST_ATOMIC_IPC_ATOMIC_HPP_INCLUDED_ 16 17 #include <cstddef> 18 #include <boost/static_assert.hpp> 19 #include <boost/memory_order.hpp> 20 #include <boost/atomic/capabilities.hpp> 21 #include <boost/atomic/detail/config.hpp> 22 #include <boost/atomic/detail/classify.hpp> 23 #include <boost/atomic/detail/atomic_impl.hpp> 24 #include <boost/atomic/detail/type_traits/is_trivially_copyable.hpp> 25 #include <boost/atomic/detail/header.hpp> 26 27 #ifdef BOOST_HAS_PRAGMA_ONCE 28 #pragma once 29 #endif 30 31 namespace boost { 32 namespace atomics { 33 34 //! Atomic object for inter-process communication 35 template< typename T > 36 class ipc_atomic : 37 public atomics::detail::base_atomic< T, typename atomics::detail::classify< T >::type, true > 38 { 39 private: 40 typedef atomics::detail::base_atomic< T, typename atomics::detail::classify< T >::type, true > base_type; 41 typedef typename base_type::value_arg_type value_arg_type; 42 43 public: 44 typedef typename base_type::value_type value_type; 45 46 BOOST_STATIC_ASSERT_MSG(sizeof(value_type) > 0u, "boost::ipc_atomic<T> requires T to be a complete type"); 47 #if !defined(BOOST_ATOMIC_DETAIL_NO_CXX11_IS_TRIVIALLY_COPYABLE) 48 BOOST_STATIC_ASSERT_MSG(atomics::detail::is_trivially_copyable< value_type >::value, "boost::ipc_atomic<T> requires T to be a trivially copyable type"); 49 #endif 50 51 public: BOOST_DEFAULTED_FUNCTION(ipc_atomic ()BOOST_ATOMIC_DETAIL_DEF_NOEXCEPT_DECL,BOOST_ATOMIC_DETAIL_DEF_NOEXCEPT_IMPL{})52 BOOST_DEFAULTED_FUNCTION(ipc_atomic() BOOST_ATOMIC_DETAIL_DEF_NOEXCEPT_DECL, BOOST_ATOMIC_DETAIL_DEF_NOEXCEPT_IMPL {}) 53 BOOST_FORCEINLINE BOOST_ATOMIC_DETAIL_CONSTEXPR_UNION_INIT ipc_atomic(value_arg_type v) BOOST_NOEXCEPT : base_type(v) {} 54 operator =(value_arg_type v)55 BOOST_FORCEINLINE value_type operator= (value_arg_type v) BOOST_NOEXCEPT 56 { 57 this->store(v); 58 return v; 59 } 60 operator =(value_arg_type v)61 BOOST_FORCEINLINE value_type operator= (value_arg_type v) volatile BOOST_NOEXCEPT 62 { 63 this->store(v); 64 return v; 65 } 66 operator value_type() const67 BOOST_FORCEINLINE operator value_type() const volatile BOOST_NOEXCEPT 68 { 69 return this->load(); 70 } 71 72 BOOST_DELETED_FUNCTION(ipc_atomic(ipc_atomic const&)) 73 BOOST_DELETED_FUNCTION(ipc_atomic& operator= (ipc_atomic const&)) 74 BOOST_DELETED_FUNCTION(ipc_atomic& operator= (ipc_atomic const&) volatile) 75 }; 76 77 } // namespace atomics 78 79 using atomics::ipc_atomic; 80 81 } // namespace boost 82 83 #include <boost/atomic/detail/footer.hpp> 84 85 #endif // BOOST_ATOMIC_IPC_ATOMIC_HPP_INCLUDED_ 86