File: ipc_atomic.hpp

package info (click to toggle)
boost1.90 1.90.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 593,168 kB
  • sloc: cpp: 4,190,642; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,776; makefile: 1,162; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (86 lines) | stat: -rw-r--r-- 2,388 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * 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-2025 Andrey Semashev
 */
/*!
 * \file   atomic/ipc_atomic.hpp
 *
 * This header contains definition of \c ipc_atomic template.
 */

#ifndef BOOST_ATOMIC_IPC_ATOMIC_HPP_INCLUDED_
#define BOOST_ATOMIC_IPC_ATOMIC_HPP_INCLUDED_

#include <cstddef>
#include <type_traits>
#include <boost/memory_order.hpp>
#include <boost/atomic/capabilities.hpp>
#include <boost/atomic/detail/config.hpp>
#include <boost/atomic/detail/classify.hpp>
#include <boost/atomic/detail/atomic_impl.hpp>
#include <boost/atomic/detail/type_traits/is_trivially_copyable.hpp>
#include <boost/atomic/detail/header.hpp>

#ifdef BOOST_HAS_PRAGMA_ONCE
#pragma once
#endif

namespace boost {
namespace atomics {

//! Atomic object for inter-process communication
template< typename T >
class ipc_atomic :
    public atomics::detail::base_atomic< T, typename atomics::detail::classify< T >::type, true >
{
private:
    using base_type = atomics::detail::base_atomic< T, typename atomics::detail::classify< T >::type, true >;
    using value_arg_type = typename base_type::value_arg_type;

public:
    using value_type = typename base_type::value_type;

    static_assert(sizeof(value_type) > 0u, "boost::ipc_atomic<T> requires T to be a complete type");
    static_assert(atomics::detail::is_trivially_copyable< value_type >::value, "boost::ipc_atomic<T> requires T to be a trivially copyable type");

public:
    ipc_atomic() = default;

    BOOST_FORCEINLINE constexpr ipc_atomic(value_arg_type v) noexcept : base_type(v)
    {
    }

    ipc_atomic(ipc_atomic const&) = delete;
    ipc_atomic& operator= (ipc_atomic const&) = delete;
    ipc_atomic& operator= (ipc_atomic const&) volatile = delete;

    BOOST_FORCEINLINE value_type operator= (value_arg_type v) noexcept
    {
        this->store(v);
        return v;
    }

    BOOST_FORCEINLINE value_type operator= (value_arg_type v) volatile noexcept
    {
        this->store(v);
        return v;
    }

    BOOST_FORCEINLINE operator value_type() const volatile noexcept
    {
        return this->load();
    }
};

} // namespace atomics

using atomics::ipc_atomic;

} // namespace boost

#include <boost/atomic/detail/footer.hpp>

#endif // BOOST_ATOMIC_IPC_ATOMIC_HPP_INCLUDED_