atomic.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (C) 2011 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. // at this time, few compiles completely implement 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 defined(__GNUC__)
  17. # if defined(__GNUC_PATCHLEVEL__)
  18. # define BOOST_ATOMIC_GNUC_VERSION (__GNUC__ * 10000 \
  19. + __GNUC_MINOR__ * 100 \
  20. + __GNUC_PATCHLEVEL__)
  21. # else
  22. # define BOOST_LOCKFREE_GNUC_VERSION (__GNUC__ * 10000 \
  23. + __GNUC_MINOR__ * 100)
  24. # endif
  25. #endif
  26. #if (BOOST_LOCKFREE_GNUC_VERSION >= 40800) && (__cplusplus >= 201103L)
  27. #undef BOOST_LOCKFREE_NO_HDR_ATOMIC
  28. #endif
  29. #undef BOOST_LOCKFREE_GNUC_VERSION
  30. #if defined(BOOST_LOCKFREE_NO_HDR_ATOMIC)
  31. #include <boost/atomic.hpp>
  32. #else
  33. #include <atomic>
  34. #endif
  35. namespace boost {
  36. namespace lockfree {
  37. namespace detail {
  38. #if defined(BOOST_LOCKFREE_NO_HDR_ATOMIC)
  39. using boost::atomic;
  40. using boost::memory_order_acquire;
  41. using boost::memory_order_consume;
  42. using boost::memory_order_relaxed;
  43. using boost::memory_order_release;
  44. #else
  45. using std::atomic;
  46. using std::memory_order_acquire;
  47. using std::memory_order_consume;
  48. using std::memory_order_relaxed;
  49. using std::memory_order_release;
  50. #endif
  51. }
  52. using detail::atomic;
  53. using detail::memory_order_acquire;
  54. using detail::memory_order_consume;
  55. using detail::memory_order_relaxed;
  56. using detail::memory_order_release;
  57. }}
  58. #endif /* BOOST_LOCKFREE_DETAIL_ATOMIC_HPP */