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 12 #ifndef BOOST_MEMORY_ORDER_HPP_INCLUDED 13 #define BOOST_MEMORY_ORDER_HPP_INCLUDED 14 15 #include <boost/config.hpp> 16 17 #if defined(BOOST_HAS_PRAGMA_ONCE) 18 # pragma once 19 #endif 20 21 namespace boost 22 { 23 24 // 25 // Enum values are chosen so that code that needs to insert 26 // a trailing fence for acquire semantics can use a single 27 // test such as: 28 // 29 // if( mo & memory_order_acquire ) { ...fence... } 30 // 31 // For leading fences one can use: 32 // 33 // if( mo & memory_order_release ) { ...fence... } 34 // 35 // Architectures such as Alpha that need a fence on consume 36 // can use: 37 // 38 // if( mo & ( memory_order_acquire | memory_order_consume ) ) { ...fence... } 39 // 40 // The values are also in the order of increasing "strength" 41 // of the fences so that success/failure orders can be checked 42 // efficiently in compare_exchange methods. 43 // 44 45 #if !defined(BOOST_NO_CXX11_SCOPED_ENUMS) 46 47 enum class memory_order : unsigned int 48 { 49 relaxed = 0, 50 consume = 1, 51 acquire = 2, 52 release = 4, 53 acq_rel = 6, // acquire | release 54 seq_cst = 14 // acq_rel | 8 55 }; 56 57 #if !defined(BOOST_NO_CXX17_INLINE_VARIABLES) 58 #define BOOST_MEMORY_ORDER_INLINE_VARIABLE inline 59 #else 60 #define BOOST_MEMORY_ORDER_INLINE_VARIABLE 61 #endif 62 63 BOOST_MEMORY_ORDER_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_relaxed = memory_order::relaxed; 64 BOOST_MEMORY_ORDER_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_consume = memory_order::consume; 65 BOOST_MEMORY_ORDER_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_acquire = memory_order::acquire; 66 BOOST_MEMORY_ORDER_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_release = memory_order::release; 67 BOOST_MEMORY_ORDER_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_acq_rel = memory_order::acq_rel; 68 BOOST_MEMORY_ORDER_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_seq_cst = memory_order::seq_cst; 69 70 #undef BOOST_MEMORY_ORDER_INLINE_VARIABLE 71 72 #else // !defined(BOOST_NO_CXX11_SCOPED_ENUMS) 73 74 enum memory_order 75 { 76 memory_order_relaxed = 0, 77 memory_order_consume = 1, 78 memory_order_acquire = 2, 79 memory_order_release = 4, 80 memory_order_acq_rel = 6, // acquire | release 81 memory_order_seq_cst = 14 // acq_rel | 8 82 }; 83 84 #endif // !defined(BOOST_NO_CXX11_SCOPED_ENUMS) 85 86 } // namespace boost 87 88 #endif // #ifndef BOOST_MEMORY_ORDER_HPP_INCLUDED 89