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)
6 * Copyright (c) 2014 Andrey Semashev
9 * \file atomic/detail/cas_based_exchange.hpp
11 * This header contains CAS-based implementation of exchange operation.
14 #ifndef BOOST_ATOMIC_DETAIL_CAS_BASED_EXCHANGE_HPP_INCLUDED_
15 #define BOOST_ATOMIC_DETAIL_CAS_BASED_EXCHANGE_HPP_INCLUDED_
17 #include <boost/memory_order.hpp>
18 #include <boost/atomic/detail/config.hpp>
19 #include <boost/atomic/detail/header.hpp>
21 #ifdef BOOST_HAS_PRAGMA_ONCE
29 template< typename Base >
30 struct cas_based_exchange :
33 typedef typename Base::storage_type storage_type;
35 static BOOST_FORCEINLINE storage_type exchange(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
38 atomics::detail::non_atomic_load(storage, old_val);
39 while (!Base::compare_exchange_weak(storage, old_val, v, order, memory_order_relaxed)) {}
45 } // namespace atomics
48 #include <boost/atomic/detail/footer.hpp>
50 #endif // BOOST_ATOMIC_DETAIL_CAS_BASED_EXCHANGE_HPP_INCLUDED_