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/detail/aligned_variable.hpp 10 * 11 * This header defines a convenience macro for declaring aligned variables 12 */ 13 14 #ifndef BOOST_ATOMIC_DETAIL_ALIGNED_VARIABLE_HPP_INCLUDED_ 15 #define BOOST_ATOMIC_DETAIL_ALIGNED_VARIABLE_HPP_INCLUDED_ 16 17 #include <boost/atomic/detail/config.hpp> 18 #if defined(BOOST_ATOMIC_DETAIL_NO_CXX11_ALIGNAS) 19 #include <boost/config/helper_macros.hpp> 20 #include <boost/type_traits/type_with_alignment.hpp> 21 #endif 22 #include <boost/atomic/detail/header.hpp> 23 24 #ifdef BOOST_HAS_PRAGMA_ONCE 25 #pragma once 26 #endif 27 28 #if !defined(BOOST_ATOMIC_DETAIL_NO_CXX11_ALIGNAS) 29 30 #define BOOST_ATOMIC_DETAIL_ALIGNED_VAR(var_alignment, var_type, var_name) \ 31 alignas(var_alignment) var_type var_name 32 33 #define BOOST_ATOMIC_DETAIL_ALIGNED_VAR_TPL(var_alignment, var_type, var_name) \ 34 alignas(var_alignment) var_type var_name 35 36 #else // !defined(BOOST_ATOMIC_DETAIL_NO_CXX11_ALIGNAS) 37 38 // Note: Some compilers cannot use constant expressions in alignment attributes or alignas, so we have to use the union trick 39 #define BOOST_ATOMIC_DETAIL_ALIGNED_VAR(var_alignment, var_type, var_name) \ 40 union \ 41 { \ 42 var_type var_name; \ 43 boost::type_with_alignment< var_alignment >::type BOOST_JOIN(var_name, _aligner); \ 44 } 45 46 #define BOOST_ATOMIC_DETAIL_ALIGNED_VAR_TPL(var_alignment, var_type, var_name) \ 47 union \ 48 { \ 49 var_type var_name; \ 50 typename boost::type_with_alignment< var_alignment >::type BOOST_JOIN(var_name, _aligner); \ 51 } 52 53 #endif // !defined(BOOST_ATOMIC_DETAIL_NO_CXX11_ALIGNAS) 54 55 #include <boost/atomic/detail/footer.hpp> 56 57 #endif // BOOST_ATOMIC_DETAIL_ALIGNED_VARIABLE_HPP_INCLUDED_ 58