atomic.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright (C) 2011-2013, 2016 Tim Blechmann
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_LOCKFREE_DETAIL_ATOMIC_HPP
  7. #define BOOST_LOCKFREE_DETAIL_ATOMIC_HPP
  8. #include <boost/config.hpp>
  9. #ifndef BOOST_LOCKFREE_FORCE_STD_ATOMIC
  10. #define BOOST_LOCKFREE_NO_HDR_ATOMIC
  11. // MSVC supports atomic<> from version 2012 onwards.
  12. #if defined(BOOST_MSVC) && (BOOST_MSVC >= 1700)
  13. #undef BOOST_LOCKFREE_NO_HDR_ATOMIC
  14. #endif
  15. // GCC supports atomic<> from version 4.8 onwards.
  16. #if (BOOST_GCC >= 40800) && (__cplusplus >= 201103L)
  17. #undef BOOST_LOCKFREE_NO_HDR_ATOMIC
  18. #endif
  19. // Apple clang is 2 mayor versions ahead, but in fact 1 minor version behind
  20. #ifdef BOOST_CLANG
  21. #define BOOST_ATOMIC_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
  22. #if defined(__apple_build_version__) && (BOOST_ATOMIC_CLANG_VERSION >= 60100) && (__cplusplus >= 201103L)
  23. #undef BOOST_LOCKFREE_NO_HDR_ATOMIC
  24. #endif
  25. #if !defined(__apple_build_version__) && (BOOST_ATOMIC_CLANG_VERSION >= 30600) && (__cplusplus >= 201103L)
  26. #undef BOOST_LOCKFREE_NO_HDR_ATOMIC
  27. #endif
  28. #undef BOOST_ATOMIC_CLANG_VERSION
  29. #endif // BOOST_CLANG
  30. // Stdlib should also be checked
  31. #include <boost/config.hpp>
  32. #if defined(BOOST_NO_CXX11_HDR_ATOMIC) && !defined(BOOST_LOCKFREE_NO_HDR_ATOMIC)
  33. # define BOOST_LOCKFREE_NO_HDR_ATOMIC
  34. #endif
  35. #endif // BOOST_LOCKFREE_FORCE_STD_ATOMIC
  36. #if defined(BOOST_LOCKFREE_NO_HDR_ATOMIC) || defined(BOOST_LOCKFREE_FORCE_BOOST_ATOMIC)
  37. #include <boost/atomic.hpp>
  38. #else
  39. #include <atomic>
  40. #endif
  41. namespace boost {
  42. namespace lockfree {
  43. namespace detail {
  44. #if defined(BOOST_LOCKFREE_NO_HDR_ATOMIC) || defined(BOOST_LOCKFREE_FORCE_BOOST_ATOMIC)
  45. using boost::atomic;
  46. using boost::memory_order_acquire;
  47. using boost::memory_order_consume;
  48. using boost::memory_order_relaxed;
  49. using boost::memory_order_release;
  50. #else
  51. using std::atomic;
  52. using std::memory_order_acquire;
  53. using std::memory_order_consume;
  54. using std::memory_order_relaxed;
  55. using std::memory_order_release;
  56. #endif
  57. }
  58. using detail::atomic;
  59. using detail::memory_order_acquire;
  60. using detail::memory_order_consume;
  61. using detail::memory_order_relaxed;
  62. using detail::memory_order_release;
  63. }}
  64. #endif /* BOOST_LOCKFREE_DETAIL_ATOMIC_HPP */