• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  Copyright (c) 2020 Andrey Semashev
2 //
3 //  Distributed under the Boost Software License, Version 1.0.
4 //  See accompanying file LICENSE_1_0.txt or copy at
5 //  http://www.boost.org/LICENSE_1_0.txt)
6 
7 #ifndef BOOST_ATOMIC_TEST_ATOMIC_WRAPPER_HPP_INCLUDED_
8 #define BOOST_ATOMIC_TEST_ATOMIC_WRAPPER_HPP_INCLUDED_
9 
10 #include <boost/atomic/atomic.hpp>
11 #include <boost/atomic/atomic_ref.hpp>
12 #include <boost/atomic/ipc_atomic.hpp>
13 #include <boost/atomic/ipc_atomic_ref.hpp>
14 #include <boost/config.hpp>
15 #include "aligned_object.hpp"
16 
17 //! Wrapper type for atomic template
18 template< typename T >
19 struct atomic_wrapper
20 {
21     typedef boost::atomic< T > atomic_type;
22     typedef atomic_type& atomic_reference_type;
23 
24     atomic_type a;
25 
atomic_wrapperatomic_wrapper26     BOOST_DEFAULTED_FUNCTION(atomic_wrapper(), {})
27     explicit atomic_wrapper(T const& value) : a(value) {}
28 };
29 
30 //! Wrapper type for atomic_ref template
31 template< typename T >
32 struct atomic_ref_wrapper
33 {
34     typedef boost::atomic_ref< T > atomic_type;
35     typedef atomic_type const& atomic_reference_type;
36 
37     aligned_object< T, atomic_type::required_alignment > object;
38     const atomic_type a;
39 
atomic_ref_wrapperatomic_ref_wrapper40     atomic_ref_wrapper() : a(object.get()) {}
atomic_ref_wrapperatomic_ref_wrapper41     explicit atomic_ref_wrapper(T const& value) : object(value), a(object.get()) {}
42 };
43 
44 //! Wrapper type for ipc_atomic template
45 template< typename T >
46 struct ipc_atomic_wrapper
47 {
48     typedef boost::ipc_atomic< T > atomic_type;
49     typedef atomic_type& atomic_reference_type;
50 
51     atomic_type a;
52 
ipc_atomic_wrapperipc_atomic_wrapper53     BOOST_DEFAULTED_FUNCTION(ipc_atomic_wrapper(), {})
54     explicit ipc_atomic_wrapper(T const& value) : a(value) {}
55 };
56 
57 //! Wrapper type for atomic_ref template
58 template< typename T >
59 struct ipc_atomic_ref_wrapper
60 {
61     typedef boost::ipc_atomic_ref< T > atomic_type;
62     typedef atomic_type const& atomic_reference_type;
63 
64     aligned_object< T, atomic_type::required_alignment > object;
65     const atomic_type a;
66 
ipc_atomic_ref_wrapperipc_atomic_ref_wrapper67     ipc_atomic_ref_wrapper() : a(object.get()) {}
ipc_atomic_ref_wrapperipc_atomic_ref_wrapper68     explicit ipc_atomic_ref_wrapper(T const& value) : object(value), a(object.get()) {}
69 };
70 
71 #endif // BOOST_ATOMIC_TEST_ATOMIC_WRAPPER_HPP_INCLUDED_
72