]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/atomic/detail/core_ops_cas_based.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / atomic / detail / core_ops_cas_based.hpp
CommitLineData
7c673cae
FG
1/*
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
5 *
6 * Copyright (c) 2014 Andrey Semashev
7 */
8/*!
20effc67 9 * \file atomic/detail/core_ops_cas_based.hpp
7c673cae 10 *
20effc67 11 * This header contains CAS-based implementation of core atomic operations.
7c673cae
FG
12 */
13
20effc67
TL
14#ifndef BOOST_ATOMIC_DETAIL_CORE_OPS_CAS_BASED_HPP_INCLUDED_
15#define BOOST_ATOMIC_DETAIL_CORE_OPS_CAS_BASED_HPP_INCLUDED_
7c673cae
FG
16
17#include <boost/memory_order.hpp>
18#include <boost/atomic/detail/config.hpp>
20effc67 19#include <boost/atomic/detail/header.hpp>
7c673cae
FG
20
21#ifdef BOOST_HAS_PRAGMA_ONCE
22#pragma once
23#endif
24
25namespace boost {
26namespace atomics {
27namespace detail {
28
29template< typename Base >
20effc67 30struct core_operations_cas_based :
7c673cae
FG
31 public Base
32{
33 typedef typename Base::storage_type storage_type;
34
11fdf7f2
TL
35 static BOOST_CONSTEXPR_OR_CONST bool full_cas_based = true;
36
7c673cae
FG
37 static BOOST_FORCEINLINE storage_type fetch_add(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
38 {
39 storage_type old_val;
40 atomics::detail::non_atomic_load(storage, old_val);
41 while (!Base::compare_exchange_weak(storage, old_val, old_val + v, order, memory_order_relaxed)) {}
42 return old_val;
43 }
44
45 static BOOST_FORCEINLINE storage_type fetch_sub(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
46 {
47 storage_type old_val;
48 atomics::detail::non_atomic_load(storage, old_val);
49 while (!Base::compare_exchange_weak(storage, old_val, old_val - v, order, memory_order_relaxed)) {}
50 return old_val;
51 }
52
53 static BOOST_FORCEINLINE storage_type fetch_and(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
54 {
55 storage_type old_val;
56 atomics::detail::non_atomic_load(storage, old_val);
57 while (!Base::compare_exchange_weak(storage, old_val, old_val & v, order, memory_order_relaxed)) {}
58 return old_val;
59 }
60
61 static BOOST_FORCEINLINE storage_type fetch_or(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
62 {
63 storage_type old_val;
64 atomics::detail::non_atomic_load(storage, old_val);
65 while (!Base::compare_exchange_weak(storage, old_val, old_val | v, order, memory_order_relaxed)) {}
66 return old_val;
67 }
68
69 static BOOST_FORCEINLINE storage_type fetch_xor(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
70 {
71 storage_type old_val;
72 atomics::detail::non_atomic_load(storage, old_val);
73 while (!Base::compare_exchange_weak(storage, old_val, old_val ^ v, order, memory_order_relaxed)) {}
74 return old_val;
75 }
76
77 static BOOST_FORCEINLINE bool test_and_set(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
78 {
79 return !!Base::exchange(storage, (storage_type)1, order);
80 }
81
82 static BOOST_FORCEINLINE void clear(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
83 {
84 Base::store(storage, (storage_type)0, order);
85 }
86};
87
88} // namespace detail
89} // namespace atomics
90} // namespace boost
91
20effc67
TL
92#include <boost/atomic/detail/footer.hpp>
93
94#endif // BOOST_ATOMIC_DETAIL_CORE_OPS_CAS_BASED_HPP_INCLUDED_