atomic.hpp 3.1 KB

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