Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:33:50

0001 /*
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * Copyright (c) 2014 Andrey Semashev
0007  */
0008 /*!
0009  * \file   atomic/detail/cas_based_exchange.hpp
0010  *
0011  * This header contains CAS-based implementation of exchange operation.
0012  */
0013 
0014 #ifndef BOOST_ATOMIC_DETAIL_CAS_BASED_EXCHANGE_HPP_INCLUDED_
0015 #define BOOST_ATOMIC_DETAIL_CAS_BASED_EXCHANGE_HPP_INCLUDED_
0016 
0017 #include <boost/memory_order.hpp>
0018 #include <boost/atomic/detail/config.hpp>
0019 #include <boost/atomic/detail/header.hpp>
0020 
0021 #ifdef BOOST_HAS_PRAGMA_ONCE
0022 #pragma once
0023 #endif
0024 
0025 namespace boost {
0026 namespace atomics {
0027 namespace detail {
0028 
0029 template< typename Base >
0030 struct cas_based_exchange :
0031     public Base
0032 {
0033     typedef typename Base::storage_type storage_type;
0034 
0035     static BOOST_FORCEINLINE storage_type exchange(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
0036     {
0037         storage_type old_val;
0038         atomics::detail::non_atomic_load(storage, old_val);
0039         while (!Base::compare_exchange_weak(storage, old_val, v, order, memory_order_relaxed)) {}
0040         return old_val;
0041     }
0042 };
0043 
0044 } // namespace detail
0045 } // namespace atomics
0046 } // namespace boost
0047 
0048 #include <boost/atomic/detail/footer.hpp>
0049 
0050 #endif // BOOST_ATOMIC_DETAIL_CAS_BASED_EXCHANGE_HPP_INCLUDED_