atomic.hpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #ifndef BOOST_MATH_ATOMIC_DETAIL_HPP
  7. #define BOOST_MATH_ATOMIC_DETAIL_HPP
  8. #include <boost/config.hpp>
  9. #include <boost/math/tools/cxx03_warn.hpp>
  10. #ifdef BOOST_HAS_THREADS
  11. #ifndef BOOST_NO_CXX11_HDR_ATOMIC
  12. # include <atomic>
  13. # define BOOST_MATH_ATOMIC_NS std
  14. namespace boost {
  15. namespace math {
  16. namespace detail {
  17. #if ATOMIC_INT_LOCK_FREE == 2
  18. typedef std::atomic<int> atomic_counter_type;
  19. typedef std::atomic<unsigned> atomic_unsigned_type;
  20. typedef int atomic_integer_type;
  21. typedef unsigned atomic_unsigned_integer_type;
  22. #elif ATOMIC_SHORT_LOCK_FREE == 2
  23. typedef std::atomic<short> atomic_counter_type;
  24. typedef std::atomic<unsigned short> atomic_unsigned_type;
  25. typedef short atomic_integer_type;
  26. typedef unsigned short atomic_unsigned_type;
  27. #elif ATOMIC_LONG_LOCK_FREE == 2
  28. typedef std::atomic<long> atomic_unsigned_integer_type;
  29. typedef std::atomic<unsigned long> atomic_unsigned_type;
  30. typedef unsigned long atomic_unsigned_type;
  31. typedef long atomic_integer_type;
  32. #elif ATOMIC_LLONG_LOCK_FREE == 2
  33. typedef std::atomic<long long> atomic_unsigned_integer_type;
  34. typedef std::atomic<unsigned long long> atomic_unsigned_type;
  35. typedef long long atomic_integer_type;
  36. typedef unsigned long long atomic_unsigned_integer_type;
  37. #else
  38. # define BOOST_MATH_NO_ATOMIC_INT
  39. #endif
  40. }
  41. }}
  42. #else // BOOST_NO_CXX11_HDR_ATOMIC
  43. //
  44. // We need Boost.Atomic, but on any platform that supports auto-linking we do
  45. // not need to link against a separate library:
  46. //
  47. #define BOOST_ATOMIC_NO_LIB
  48. #include <boost/atomic.hpp>
  49. # define BOOST_MATH_ATOMIC_NS boost
  50. namespace boost{ namespace math{ namespace detail{
  51. //
  52. // We need a type to use as an atomic counter:
  53. //
  54. #if BOOST_ATOMIC_INT_LOCK_FREE == 2
  55. typedef boost::atomic<int> atomic_counter_type;
  56. typedef boost::atomic<unsigned> atomic_unsigned_type;
  57. typedef int atomic_integer_type;
  58. typedef unsigned atomic_unsigned_integer_type;
  59. #elif BOOST_ATOMIC_SHORT_LOCK_FREE == 2
  60. typedef boost::atomic<short> atomic_counter_type;
  61. typedef boost::atomic<unsigned short> atomic_unsigned_type;
  62. typedef short atomic_integer_type;
  63. typedef unsigned short atomic_unsigned_integer_type;
  64. #elif BOOST_ATOMIC_LONG_LOCK_FREE == 2
  65. typedef boost::atomic<long> atomic_counter_type;
  66. typedef boost::atomic<unsigned long> atomic_unsigned_type;
  67. typedef long atomic_integer_type;
  68. typedef unsigned long atomic_unsigned_integer_type;
  69. #elif BOOST_ATOMIC_LLONG_LOCK_FREE == 2
  70. typedef boost::atomic<long long> atomic_counter_type;
  71. typedef boost::atomic<unsigned long long> atomic_unsigned_type;
  72. typedef long long atomic_integer_type;
  73. typedef unsigned long long atomic_unsigned_integer_type;
  74. #else
  75. # define BOOST_MATH_NO_ATOMIC_INT
  76. #endif
  77. }}} // namespaces
  78. #endif // BOOST_NO_CXX11_HDR_ATOMIC
  79. #else // BOOST_HAS_THREADS
  80. # define BOOST_MATH_NO_ATOMIC_INT
  81. #endif // BOOST_HAS_THREADS
  82. #endif // BOOST_MATH_ATOMIC_DETAIL_HPP