/* * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * Copyright (c) 2020-2021 Andrey Semashev */ /*! * \file atomic/ipc_atomic_ref.hpp * * This header contains definition of \c ipc_atomic_ref template. */ #ifndef ACTIV_BOOST_ATOMIC_IPC_ATOMIC_REF_HPP_INCLUDED_ #define ACTIV_BOOST_ATOMIC_IPC_ATOMIC_REF_HPP_INCLUDED_ #include #include #include #include #include #include #include #include #include #include #ifdef ACTIV_BOOST_HAS_PRAGMA_ONCE #pragma once #endif namespace Boost { namespace atomics { //! Atomic reference to external object for inter-process communication template< typename T > class ipc_atomic_ref : public atomics::detail::base_atomic_ref< T, typename atomics::detail::classify< T >::type, true > { private: typedef atomics::detail::base_atomic_ref< T, typename atomics::detail::classify< T >::type, true > base_type; typedef typename base_type::value_arg_type value_arg_type; public: typedef typename base_type::value_type value_type; ACTIV_BOOST_STATIC_ASSERT_MSG(sizeof(value_type) > 0u, "Boost::ipc_atomic_ref requires T to be a complete type"); #if !defined(ACTIV_BOOST_ATOMIC_DETAIL_NO_CXX11_IS_TRIVIALLY_COPYABLE) ACTIV_BOOST_STATIC_ASSERT_MSG(atomics::detail::is_trivially_copyable< value_type >::value, "Boost::ipc_atomic_ref requires T to be a trivially copyable type"); #endif private: typedef typename base_type::storage_type storage_type; public: ACTIV_BOOST_DEFAULTED_FUNCTION(ipc_atomic_ref(ipc_atomic_ref const& that) ACTIV_BOOST_ATOMIC_DETAIL_DEF_NOEXCEPT_DECL, ACTIV_BOOST_ATOMIC_DETAIL_DEF_NOEXCEPT_IMPL : base_type(static_cast< base_type const& >(that)) {}) ACTIV_BOOST_FORCEINLINE explicit ipc_atomic_ref(value_type& v) ACTIV_BOOST_NOEXCEPT : base_type(v) { // Check that referenced object alignment satisfies required alignment ACTIV_BOOST_ASSERT((((atomics::detail::uintptr_t)this->m_value) & (base_type::required_alignment - 1u)) == 0u); } ACTIV_BOOST_FORCEINLINE value_type operator= (value_arg_type v) const ACTIV_BOOST_NOEXCEPT { this->store(v); return v; } ACTIV_BOOST_FORCEINLINE operator value_type() const ACTIV_BOOST_NOEXCEPT { return this->load(); } ACTIV_BOOST_DELETED_FUNCTION(ipc_atomic_ref& operator= (ipc_atomic_ref const&)) }; #if !defined(ACTIV_BOOST_ATOMIC_DETAIL_NO_CXX17_DEDUCTION_GUIDES) template< typename T > ipc_atomic_ref(T&) -> ipc_atomic_ref< T >; #endif // !defined(ACTIV_BOOST_ATOMIC_DETAIL_NO_CXX17_DEDUCTION_GUIDES) //! IPC atomic reference factory function template< typename T > ACTIV_BOOST_FORCEINLINE ipc_atomic_ref< T > make_ipc_atomic_ref(T& value) ACTIV_BOOST_NOEXCEPT { return ipc_atomic_ref< T >(value); } } // namespace atomics using atomics::ipc_atomic_ref; using atomics::make_ipc_atomic_ref; } // namespace Boost #include #endif // ACTIV_BOOST_ATOMIC_IPC_ATOMIC_REF_HPP_INCLUDED_