]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/atomic/detail/cas_based_exchange.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / atomic / detail / cas_based_exchange.hpp
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 /*!
9 * \file atomic/detail/cas_based_exchange.hpp
10 *
11 * This header contains CAS-based implementation of exchange operation.
12 */
13
14 #ifndef BOOST_ATOMIC_DETAIL_CAS_BASED_EXCHANGE_HPP_INCLUDED_
15 #define BOOST_ATOMIC_DETAIL_CAS_BASED_EXCHANGE_HPP_INCLUDED_
16
17 #include <boost/memory_order.hpp>
18 #include <boost/atomic/detail/config.hpp>
19 #include <boost/atomic/detail/header.hpp>
20
21 #ifdef BOOST_HAS_PRAGMA_ONCE
22 #pragma once
23 #endif
24
25 namespace boost {
26 namespace atomics {
27 namespace detail {
28
29 template< typename Base >
30 struct cas_based_exchange :
31 public Base
32 {
33 typedef typename Base::storage_type storage_type;
34
35 static BOOST_FORCEINLINE storage_type exchange(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
36 {
37 storage_type old_val;
38 atomics::detail::non_atomic_load(storage, old_val);
39 while (!Base::compare_exchange_weak(storage, old_val, v, order, memory_order_relaxed)) {}
40 return old_val;
41 }
42 };
43
44 } // namespace detail
45 } // namespace atomics
46 } // namespace boost
47
48 #include <boost/atomic/detail/footer.hpp>
49
50 #endif // BOOST_ATOMIC_DETAIL_CAS_BASED_EXCHANGE_HPP_INCLUDED_