BVB Source Codes

mars Show ops_cas_based.hpp Source code

Return Download mars: download ops_cas_based.hpp Source code - Download mars Source code - Type:.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/ops_cas_based.hpp
  10.  *
  11.  * This header contains CAS-based implementation of the \c operations template.
  12.  */
  13.  
  14. #ifndef BOOST_ATOMIC_DETAIL_OPS_CAS_BASED_HPP_INCLUDED_
  15. #define BOOST_ATOMIC_DETAIL_OPS_CAS_BASED_HPP_INCLUDED_
  16.  
  17. #include <boost/memory_order.hpp>
  18. #include <boost/atomic/detail/config.hpp>
  19. #include <boost/atomic/detail/storage_type.hpp>
  20.  
  21. #ifdef BOOST_HAS_PRAGMA_ONCE
  22. #pragma once
  23. #endif
  24.  
  25. namespace mars_boost {} namespace boost = mars_boost; namespace mars_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. template< typename Base >
  45. struct cas_based_operations :
  46.     public Base
  47. {
  48.     typedef typename Base::storage_type storage_type;
  49.  
  50.     static BOOST_FORCEINLINE storage_type fetch_add(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  51.     {
  52.         storage_type old_val;
  53.         atomics::detail::non_atomic_load(storage, old_val);
  54.         while (!Base::compare_exchange_weak(storage, old_val, old_val + v, order, memory_order_relaxed)) {}
  55.         return old_val;
  56.     }
  57.  
  58.     static BOOST_FORCEINLINE storage_type fetch_sub(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  59.     {
  60.         storage_type old_val;
  61.         atomics::detail::non_atomic_load(storage, old_val);
  62.         while (!Base::compare_exchange_weak(storage, old_val, old_val - v, order, memory_order_relaxed)) {}
  63.         return old_val;
  64.     }
  65.  
  66.     static BOOST_FORCEINLINE storage_type fetch_and(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  67.     {
  68.         storage_type old_val;
  69.         atomics::detail::non_atomic_load(storage, old_val);
  70.         while (!Base::compare_exchange_weak(storage, old_val, old_val & v, order, memory_order_relaxed)) {}
  71.         return old_val;
  72.     }
  73.  
  74.     static BOOST_FORCEINLINE storage_type fetch_or(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  75.     {
  76.         storage_type old_val;
  77.         atomics::detail::non_atomic_load(storage, old_val);
  78.         while (!Base::compare_exchange_weak(storage, old_val, old_val | v, order, memory_order_relaxed)) {}
  79.         return old_val;
  80.     }
  81.  
  82.     static BOOST_FORCEINLINE storage_type fetch_xor(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  83.     {
  84.         storage_type old_val;
  85.         atomics::detail::non_atomic_load(storage, old_val);
  86.         while (!Base::compare_exchange_weak(storage, old_val, old_val ^ v, order, memory_order_relaxed)) {}
  87.         return old_val;
  88.     }
  89.  
  90.     static BOOST_FORCEINLINE bool test_and_set(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  91.     {
  92.         return !!Base::exchange(storage, (storage_type)1, order);
  93.     }
  94.  
  95.     static BOOST_FORCEINLINE void clear(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  96.     {
  97.         Base::store(storage, (storage_type)0, order);
  98.     }
  99. };
  100.  
  101. } // namespace detail
  102. } // namespace atomics
  103. } // namespace mars_boost
  104.  
  105. #endif // BOOST_ATOMIC_DETAIL_OPS_CAS_BASED_HPP_INCLUDED_
  106.  
downloadops_cas_based.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top