| 1 | /////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright 2017 John Maddock |
| 3 | // Distributed under the Boost |
| 4 | // Software License, Version 1.0. (See accompanying file |
| 5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | |
| 7 | #ifndef BOOST_MATH_ATOMIC_DETAIL_HPP |
| 8 | #define BOOST_MATH_ATOMIC_DETAIL_HPP |
| 9 | |
| 10 | #include <boost/config.hpp> |
| 11 | #include <boost/math/tools/cxx03_warn.hpp> |
| 12 | |
| 13 | #ifdef BOOST_HAS_THREADS |
| 14 | |
| 15 | #ifndef BOOST_NO_CXX11_HDR_ATOMIC |
| 16 | # include <atomic> |
| 17 | # define BOOST_MATH_ATOMIC_NS std |
| 18 | namespace boost { |
| 19 | namespace math { |
| 20 | namespace detail { |
| 21 | #if ATOMIC_INT_LOCK_FREE == 2 |
| 22 | typedef std::atomic<int> atomic_counter_type; |
| 23 | typedef std::atomic<unsigned> atomic_unsigned_type; |
| 24 | typedef int atomic_integer_type; |
| 25 | typedef unsigned atomic_unsigned_integer_type; |
| 26 | #elif ATOMIC_SHORT_LOCK_FREE == 2 |
| 27 | typedef std::atomic<short> atomic_counter_type; |
| 28 | typedef std::atomic<unsigned short> atomic_unsigned_type; |
| 29 | typedef short atomic_integer_type; |
| 30 | typedef unsigned short atomic_unsigned_type; |
| 31 | #elif ATOMIC_LONG_LOCK_FREE == 2 |
| 32 | typedef std::atomic<long> atomic_unsigned_integer_type; |
| 33 | typedef std::atomic<unsigned long> atomic_unsigned_type; |
| 34 | typedef unsigned long atomic_unsigned_type; |
| 35 | typedef long atomic_integer_type; |
| 36 | #elif ATOMIC_LLONG_LOCK_FREE == 2 |
| 37 | typedef std::atomic<long long> atomic_unsigned_integer_type; |
| 38 | typedef std::atomic<unsigned long long> atomic_unsigned_type; |
| 39 | typedef long long atomic_integer_type; |
| 40 | typedef unsigned long long atomic_unsigned_integer_type; |
| 41 | #else |
| 42 | # define BOOST_MATH_NO_ATOMIC_INT |
| 43 | #endif |
| 44 | } |
| 45 | }} |
| 46 | #else // BOOST_NO_CXX11_HDR_ATOMIC |
| 47 | // |
| 48 | // We need Boost.Atomic, but on any platform that supports auto-linking we do |
| 49 | // not need to link against a separate library: |
| 50 | // |
| 51 | #define BOOST_ATOMIC_NO_LIB |
| 52 | #include <boost/atomic.hpp> |
| 53 | # define BOOST_MATH_ATOMIC_NS boost |
| 54 | |
| 55 | namespace boost{ namespace math{ namespace detail{ |
| 56 | |
| 57 | // |
| 58 | // We need a type to use as an atomic counter: |
| 59 | // |
| 60 | #if BOOST_ATOMIC_INT_LOCK_FREE == 2 |
| 61 | typedef boost::atomic<int> atomic_counter_type; |
| 62 | typedef boost::atomic<unsigned> atomic_unsigned_type; |
| 63 | typedef int atomic_integer_type; |
| 64 | typedef unsigned atomic_unsigned_integer_type; |
| 65 | #elif BOOST_ATOMIC_SHORT_LOCK_FREE == 2 |
| 66 | typedef boost::atomic<short> atomic_counter_type; |
| 67 | typedef boost::atomic<unsigned short> atomic_unsigned_type; |
| 68 | typedef short atomic_integer_type; |
| 69 | typedef unsigned short atomic_unsigned_integer_type; |
| 70 | #elif BOOST_ATOMIC_LONG_LOCK_FREE == 2 |
| 71 | typedef boost::atomic<long> atomic_counter_type; |
| 72 | typedef boost::atomic<unsigned long> atomic_unsigned_type; |
| 73 | typedef long atomic_integer_type; |
| 74 | typedef unsigned long atomic_unsigned_integer_type; |
| 75 | #elif BOOST_ATOMIC_LLONG_LOCK_FREE == 2 |
| 76 | typedef boost::atomic<long long> atomic_counter_type; |
| 77 | typedef boost::atomic<unsigned long long> atomic_unsigned_type; |
| 78 | typedef long long atomic_integer_type; |
| 79 | typedef unsigned long long atomic_unsigned_integer_type; |
| 80 | #else |
| 81 | # define BOOST_MATH_NO_ATOMIC_INT |
| 82 | #endif |
| 83 | |
| 84 | }}} // namespaces |
| 85 | |
| 86 | #endif // BOOST_NO_CXX11_HDR_ATOMIC |
| 87 | |
| 88 | #else // BOOST_HAS_THREADS |
| 89 | |
| 90 | # define BOOST_MATH_NO_ATOMIC_INT |
| 91 | |
| 92 | #endif // BOOST_HAS_THREADS |
| 93 | |
| 94 | #endif // BOOST_MATH_ATOMIC_DETAIL_HPP |
| 95 | |