BVB Source Codes

mars Show ops_emulated.hpp Source code

Return Download mars: download ops_emulated.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_emulated.hpp
  10.  *
  11.  * This header contains lockpool-based implementation of the \c operations template.
  12.  */
  13.  
  14. #ifndef BOOST_ATOMIC_DETAIL_OPS_EMULATED_HPP_INCLUDED_
  15. #define BOOST_ATOMIC_DETAIL_OPS_EMULATED_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. #include <boost/atomic/detail/operations_fwd.hpp>
  22. #include <boost/atomic/detail/lockpool.hpp>
  23. #include <boost/atomic/capabilities.hpp>
  24.  
  25. #ifdef BOOST_HAS_PRAGMA_ONCE
  26. #pragma once
  27. #endif
  28.  
  29. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  30. namespace atomics {
  31. namespace detail {
  32.  
  33. template< typename T >
  34. struct emulated_operations
  35. {
  36.     typedef T storage_type;
  37.  
  38.     static BOOST_FORCEINLINE void store(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
  39.     {
  40.         lockpool::scoped_lock lock(&storage);
  41.         const_cast< storage_type& >(storage) = v;
  42.     }
  43.  
  44.     static BOOST_FORCEINLINE storage_type load(storage_type const volatile& storage, memory_order) BOOST_NOEXCEPT
  45.     {
  46.         lockpool::scoped_lock lock(&storage);
  47.         return const_cast< storage_type const& >(storage);
  48.     }
  49.  
  50.     static BOOST_FORCEINLINE storage_type fetch_add(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
  51.     {
  52.         storage_type& s = const_cast< storage_type& >(storage);
  53.         lockpool::scoped_lock lock(&storage);
  54.         storage_type old_val = s;
  55.         s += v;
  56.         return old_val;
  57.     }
  58.  
  59.     static BOOST_FORCEINLINE storage_type fetch_sub(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
  60.     {
  61.         storage_type& s = const_cast< storage_type& >(storage);
  62.         lockpool::scoped_lock lock(&storage);
  63.         storage_type old_val = s;
  64.         s -= v;
  65.         return old_val;
  66.     }
  67.  
  68.     static BOOST_FORCEINLINE storage_type exchange(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
  69.     {
  70.         storage_type& s = const_cast< storage_type& >(storage);
  71.         lockpool::scoped_lock lock(&storage);
  72.         storage_type old_val = s;
  73.         s = v;
  74.         return old_val;
  75.     }
  76.  
  77.     static BOOST_FORCEINLINE bool compare_exchange_strong(
  78.         storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order, memory_order) BOOST_NOEXCEPT
  79.     {
  80.         storage_type& s = const_cast< storage_type& >(storage);
  81.         lockpool::scoped_lock lock(&storage);
  82.         storage_type old_val = s;
  83.         const bool res = old_val == expected;
  84.         if (res)
  85.             s = desired;
  86.         expected = old_val;
  87.  
  88.         return res;
  89.     }
  90.  
  91.     static BOOST_FORCEINLINE bool compare_exchange_weak(
  92.         storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order success_order, memory_order failure_order) BOOST_NOEXCEPT
  93.     {
  94.         // Note: This function is the exact copy of compare_exchange_strong. The reason we're not just forwarding the call
  95.         // is that MSVC-12 ICEs in this case.
  96.         storage_type& s = const_cast< storage_type& >(storage);
  97.         lockpool::scoped_lock lock(&storage);
  98.         storage_type old_val = s;
  99.         const bool res = old_val == expected;
  100.         if (res)
  101.             s = desired;
  102.         expected = old_val;
  103.  
  104.         return res;
  105.     }
  106.  
  107.     static BOOST_FORCEINLINE storage_type fetch_and(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
  108.     {
  109.         storage_type& s = const_cast< storage_type& >(storage);
  110.         lockpool::scoped_lock lock(&storage);
  111.         storage_type old_val = s;
  112.         s &= v;
  113.         return old_val;
  114.     }
  115.  
  116.     static BOOST_FORCEINLINE storage_type fetch_or(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
  117.     {
  118.         storage_type& s = const_cast< storage_type& >(storage);
  119.         lockpool::scoped_lock lock(&storage);
  120.         storage_type old_val = s;
  121.         s |= v;
  122.         return old_val;
  123.     }
  124.  
  125.     static BOOST_FORCEINLINE storage_type fetch_xor(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
  126.     {
  127.         storage_type& s = const_cast< storage_type& >(storage);
  128.         lockpool::scoped_lock lock(&storage);
  129.         storage_type old_val = s;
  130.         s ^= v;
  131.         return old_val;
  132.     }
  133.  
  134.     static BOOST_FORCEINLINE bool test_and_set(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  135.     {
  136.         return !!exchange(storage, (storage_type)1, order);
  137.     }
  138.  
  139.     static BOOST_FORCEINLINE void clear(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  140.     {
  141.         store(storage, (storage_type)0, order);
  142.     }
  143.  
  144.     static BOOST_FORCEINLINE bool is_lock_free(storage_type const volatile&) BOOST_NOEXCEPT
  145.     {
  146.         return false;
  147.     }
  148. };
  149.  
  150. template< std::size_t Size, bool Signed >
  151. struct operations :
  152.     public emulated_operations< typename make_storage_type< Size, Signed >::type >
  153. {
  154.     typedef typename make_storage_type< Size, Signed >::aligned aligned_storage_type;
  155. };
  156.  
  157. } // namespace detail
  158. } // namespace atomics
  159. } // namespace mars_boost
  160.  
  161. #endif // BOOST_ATOMIC_DETAIL_OPS_EMULATED_HPP_INCLUDED_
  162.  
downloadops_emulated.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