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
21namespace 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
47enum 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
57BOOST_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_relaxed = memory_order::relaxed;
58BOOST_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_consume = memory_order::consume;
59BOOST_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_acquire = memory_order::acquire;
60BOOST_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_release = memory_order::release;
61BOOST_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_acq_rel = memory_order::acq_rel;
62BOOST_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST memory_order memory_order_seq_cst = memory_order::seq_cst;
63
64#undef BOOST_MEMORY_ORDER_INLINE_VARIABLE
65
66#else // !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
67
68enum memory_order
69{
70 memory_order_relaxed = 0,
71 memory_order_consume = 1,
72 memory_order_acquire = 2,
73 memory_order_release = 4,
74 memory_order_acq_rel = 6, // acquire | release
75 memory_order_seq_cst = 14 // acq_rel | 8
76};
77
78#endif // !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
79
80} // namespace boost
81
82#endif // #ifndef BOOST_MEMORY_ORDER_HPP_INCLUDED
83

source code of boost/libs/atomic/include/boost/memory_order.hpp