memory_order.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // boost/memory_order.hpp
  2. //
  3. // Defines enum boost::memory_order per the C++0x working draft
  4. //
  5. // Copyright (c) 2008, 2009 Peter Dimov
  6. // Copyright (c) 2018 Andrey Semashev
  7. //
  8. // Distributed under the Boost Software License, Version 1.0.
  9. // See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #ifndef BOOST_MEMORY_ORDER_HPP_INCLUDED
  12. #define BOOST_MEMORY_ORDER_HPP_INCLUDED
  13. #include <boost/config.hpp>
  14. #if defined(BOOST_HAS_PRAGMA_ONCE)
  15. # pragma once
  16. #endif
  17. namespace boost
  18. {
  19. //
  20. // Enum values are chosen so that code that needs to insert
  21. // a trailing fence for acquire semantics can use a single
  22. // test such as:
  23. //
  24. // if( mo & memory_order_acquire ) { ...fence... }
  25. //
  26. // For leading fences one can use:
  27. //
  28. // if( mo & memory_order_release ) { ...fence... }
  29. //
  30. // Architectures such as Alpha that need a fence on consume
  31. // can use:
  32. //
  33. // if( mo & ( memory_order_acquire | memory_order_consume ) ) { ...fence... }
  34. //
  35. // The values are also in the order of increasing "strength"
  36. // of the fences so that success/failure orders can be checked
  37. // efficiently in compare_exchange methods.
  38. //
  39. #if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
  40. enum class memory_order : unsigned int
  41. {
  42. relaxed = 0,
  43. consume = 1,
  44. acquire = 2,
  45. release = 4,
  46. acq_rel = 6, // acquire | release
  47. seq_cst = 14 // acq_rel | 8
  48. };
  49. #if !defined(BOOST_NO_CXX17_INLINE_VARIABLES)
  50. #define BOOST_MEMORY_ORDER_INLINE_VARIABLE inline
  51. #else
  52. #define BOOST_MEMORY_ORDER_INLINE_VARIABLE
  53. #endif
  54. BOOST_MEMORY_ORDER_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_relaxed = memory_order::relaxed;
  55. BOOST_MEMORY_ORDER_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_consume = memory_order::consume;
  56. BOOST_MEMORY_ORDER_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_acquire = memory_order::acquire;
  57. BOOST_MEMORY_ORDER_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_release = memory_order::release;
  58. BOOST_MEMORY_ORDER_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_acq_rel = memory_order::acq_rel;
  59. BOOST_MEMORY_ORDER_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_seq_cst = memory_order::seq_cst;
  60. #undef BOOST_MEMORY_ORDER_INLINE_VARIABLE
  61. #else // !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
  62. enum memory_order
  63. {
  64. memory_order_relaxed = 0,
  65. memory_order_consume = 1,
  66. memory_order_acquire = 2,
  67. memory_order_release = 4,
  68. memory_order_acq_rel = 6, // acquire | release
  69. memory_order_seq_cst = 14 // acq_rel | 8
  70. };
  71. #endif // !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
  72. } // namespace boost
  73. #endif // #ifndef BOOST_MEMORY_ORDER_HPP_INCLUDED