memory_order.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. BOOST_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_relaxed = memory_order::relaxed;
  50. BOOST_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_consume = memory_order::consume;
  51. BOOST_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_acquire = memory_order::acquire;
  52. BOOST_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_release = memory_order::release;
  53. BOOST_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_acq_rel = memory_order::acq_rel;
  54. BOOST_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_seq_cst = memory_order::seq_cst;
  55. #undef BOOST_MEMORY_ORDER_INLINE_VARIABLE
  56. #else // !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
  57. enum memory_order
  58. {
  59. memory_order_relaxed = 0,
  60. memory_order_consume = 1,
  61. memory_order_acquire = 2,
  62. memory_order_release = 4,
  63. memory_order_acq_rel = 6, // acquire | release
  64. memory_order_seq_cst = 14 // acq_rel | 8
  65. };
  66. #endif // !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
  67. } // namespace boost
  68. #endif // #ifndef BOOST_MEMORY_ORDER_HPP_INCLUDED