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)
6 * Copyright (c) 2009 Helge Bahmann
7 * Copyright (c) 2012 Tim Blechmann
8 * Copyright (c) 2013 - 2014 Andrey Semashev
11 * \file atomic/detail/storage_type.hpp
13 * This header defines underlying types used as storage
16 #ifndef BOOST_ATOMIC_DETAIL_STORAGE_TYPE_HPP_INCLUDED_
17 #define BOOST_ATOMIC_DETAIL_STORAGE_TYPE_HPP_INCLUDED_
20 #include <boost/cstdint.hpp>
21 #include <boost/atomic/detail/config.hpp>
23 #ifdef BOOST_HAS_PRAGMA_ONCE
31 template< unsigned int Size >
34 unsigned char data[Size];
36 BOOST_FORCEINLINE bool operator! () const BOOST_NOEXCEPT
39 for (unsigned int i = 0; i < Size && result; ++i)
41 result &= data[i] == 0;
46 BOOST_FORCEINLINE bool operator== (buffer_storage const& that) const BOOST_NOEXCEPT
48 return std::memcmp(data, that.data, Size) == 0;
51 BOOST_FORCEINLINE bool operator!= (buffer_storage const& that) const BOOST_NOEXCEPT
53 return std::memcmp(data, that.data, Size) != 0;
57 template< unsigned int Size, bool Signed >
58 struct make_storage_type
60 typedef buffer_storage< Size > type;
64 struct make_storage_type< 1u, false >
66 typedef boost::uint8_t type;
70 struct make_storage_type< 1u, true >
72 typedef boost::int8_t type;
76 struct make_storage_type< 2u, false >
78 typedef boost::uint16_t type;
82 struct make_storage_type< 2u, true >
84 typedef boost::int16_t type;
88 struct make_storage_type< 4u, false >
90 typedef boost::uint32_t type;
94 struct make_storage_type< 4u, true >
96 typedef boost::int32_t type;
100 struct make_storage_type< 8u, false >
102 typedef boost::uint64_t type;
106 struct make_storage_type< 8u, true >
108 typedef boost::int64_t type;
111 #if defined(BOOST_HAS_INT128)
114 struct make_storage_type< 16u, false >
116 typedef boost::uint128_type type;
120 struct make_storage_type< 16u, true >
122 typedef boost::int128_type type;
125 #elif !defined(BOOST_NO_ALIGNMENT)
127 struct BOOST_ALIGNMENT(16) storage128_t
129 boost::uint64_t data[2];
131 BOOST_FORCEINLINE bool operator! () const BOOST_NOEXCEPT
133 return data[0] == 0 && data[1] == 0;
137 BOOST_FORCEINLINE bool operator== (storage128_t const& left, storage128_t const& right) BOOST_NOEXCEPT
139 return left.data[0] == right.data[0] && left.data[1] == right.data[1];
141 BOOST_FORCEINLINE bool operator!= (storage128_t const& left, storage128_t const& right) BOOST_NOEXCEPT
143 return !(left == right);
146 template< bool Signed >
147 struct make_storage_type< 16u, Signed >
149 typedef storage128_t type;
154 template< typename T >
155 struct storage_size_of
160 value = (size == 3 ? 4 : (size >= 5 && size <= 7 ? 8 : (size >= 9 && size <= 15 ? 16 : size)))
164 } // namespace detail
165 } // namespace atomics
168 #endif // BOOST_ATOMIC_DETAIL_STORAGE_TYPE_HPP_INCLUDED_