BVB Source Codes

mars Show ops_extending_cas_based.hpp Source code

Return Download mars: download ops_extending_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_extending_cas_based.hpp
  10.  *
  11.  * This header contains a boilerplate of the \c operations template implementation that requires sign/zero extension in arithmetic operations.
  12.  */
  13.  
  14. #ifndef BOOST_ATOMIC_DETAIL_OPS_EXTENDING_CAS_BASED_HPP_INCLUDED_
  15. #define BOOST_ATOMIC_DETAIL_OPS_EXTENDING_CAS_BASED_HPP_INCLUDED_
  16.  
  17. #include <cstddef>
  18. #include <boost/memory_order.hpp>
  19. #include <boost/atomic/detail/config.hpp>
  20. #include <boost/atomic/detail/storage_type.hpp>
  21.  
  22. #ifdef BOOST_HAS_PRAGMA_ONCE
  23. #pragma once
  24. #endif
  25.  
  26. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  27. namespace atomics {
  28. namespace detail {
  29.  
  30. template< typename Base, std::size_t Size, bool Signed >
  31. struct extending_cas_based_operations :
  32.     public Base
  33. {
  34.     typedef typename Base::storage_type storage_type;
  35.     typedef typename make_storage_type< Size, Signed >::type emulated_storage_type;
  36.  
  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.         emulated_storage_type new_val;
  42.         do
  43.         {
  44.             new_val = static_cast< emulated_storage_type >(old_val) + static_cast< emulated_storage_type >(v);
  45.         }
  46.         while (!Base::compare_exchange_weak(storage, old_val, static_cast< storage_type >(new_val), order, memory_order_relaxed));
  47.         return old_val;
  48.     }
  49.  
  50.     static BOOST_FORCEINLINE storage_type fetch_sub(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.         emulated_storage_type new_val;
  55.         do
  56.         {
  57.             new_val = static_cast< emulated_storage_type >(old_val) - static_cast< emulated_storage_type >(v);
  58.         }
  59.         while (!Base::compare_exchange_weak(storage, old_val, static_cast< storage_type >(new_val), order, memory_order_relaxed));
  60.         return old_val;
  61.     }
  62. };
  63.  
  64. } // namespace detail
  65. } // namespace atomics
  66. } // namespace mars_boost
  67.  
  68. #endif // BOOST_ATOMIC_DETAIL_OPS_EXTENDING_CAS_BASED_HPP_INCLUDED_
  69.  
downloadops_extending_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