|
||||
File indexing completed on 2025-01-18 09:51:47
0001 //---------------------------------------------------------------------------- 0002 /// @file stack_cnc.hpp 0003 /// @brief This file contains the implementation concurrent stack 0004 /// 0005 /// @author Copyright (c) 2010 2015 Francisco José Tapia (fjtapia@gmail.com )\n 0006 /// Distributed under the Boost Software License, Version 1.0.\n 0007 /// ( See accompanyingfile LICENSE_1_0.txt or copy at 0008 /// http://www.boost.org/LICENSE_1_0.txt ) 0009 /// @version 0.1 0010 /// 0011 /// @remarks 0012 //----------------------------------------------------------------------------- 0013 #ifndef __BOOST_SORT_PARALLEL_DETAIL_UTIL_STACK_CNC_HPP 0014 #define __BOOST_SORT_PARALLEL_DETAIL_UTIL_STACK_CNC_HPP 0015 0016 #include <ciso646> 0017 #include <vector> 0018 #include <boost/sort/common/spinlock.hpp> 0019 0020 0021 namespace boost 0022 { 0023 namespace sort 0024 { 0025 namespace common 0026 { 0027 0028 // 0029 //########################################################################### 0030 // ## 0031 // ################################################################ ## 0032 // # # ## 0033 // # C L A S S # ## 0034 // # S T A C K _ C N C # ## 0035 // # # ## 0036 // ################################################################ ## 0037 // ## 0038 //########################################################################### 0039 // 0040 //--------------------------------------------------------------------------- 0041 /// @class stack_cnc 0042 /// @brief This class is a concurrent stack controled by a spin_lock 0043 /// @remarks 0044 //--------------------------------------------------------------------------- 0045 template<typename T, typename Allocator = std::allocator<T> > 0046 class stack_cnc 0047 { 0048 public: 0049 //------------------------------------------------------------------------ 0050 // D E F I N I T I O N S 0051 //------------------------------------------------------------------------ 0052 typedef std::vector<T, Allocator> vector_t; 0053 typedef typename vector_t::size_type size_type; 0054 typedef typename vector_t::difference_type difference_type; 0055 typedef typename vector_t::value_type value_type; 0056 typedef typename vector_t::pointer pointer; 0057 typedef typename vector_t::const_pointer const_pointer; 0058 typedef typename vector_t::reference reference; 0059 typedef typename vector_t::const_reference const_reference; 0060 typedef typename vector_t::allocator_type allocator_type; 0061 typedef Allocator alloc_t; 0062 0063 protected: 0064 //------------------------------------------------------------------------- 0065 // INTERNAL VARIABLES 0066 //------------------------------------------------------------------------- 0067 vector_t v_t; 0068 mutable spinlock_t spl; 0069 0070 public: 0071 // 0072 //------------------------------------------------------------------------- 0073 // function : stack_cnc 0074 /// @brief constructor 0075 //------------------------------------------------------------------------- 0076 explicit stack_cnc(void): v_t() { }; 0077 0078 // 0079 //------------------------------------------------------------------------- 0080 // function : stack_cnc 0081 /// @brief Move constructor 0082 //------------------------------------------------------------------------- 0083 stack_cnc(stack_cnc &&) = delete; 0084 // 0085 //------------------------------------------------------------------------- 0086 // function : ~stack_cnc 0087 /// @brief Destructor 0088 //------------------------------------------------------------------------- 0089 virtual ~stack_cnc(void) { v_t.clear(); }; 0090 0091 //------------------------------------------------------------------------- 0092 // function : emplace_back 0093 /// @brief Insert one element in the back of the container 0094 /// @param args : group of arguments for to build the object to insert. Can 0095 /// be values, references or rvalues 0096 //------------------------------------------------------------------------- 0097 template<class ... Args> 0098 void emplace_back(Args &&... args) 0099 { 0100 std::lock_guard < spinlock_t > guard(spl); 0101 v_t.emplace_back(std::forward< Args > (args)...); 0102 } 0103 0104 // 0105 //------------------------------------------------------------------------- 0106 // function :pop_move_back 0107 /// @brief if exist, move the last element to P, and delete it 0108 /// @param P : reference to a variable where move the element 0109 /// @return true - Element moved and deleted 0110 /// false - Empty stack_cnc 0111 //------------------------------------------------------------------------- 0112 bool pop_move_back(value_type &P) 0113 { 0114 std::lock_guard < spinlock_t > S(spl); 0115 if (v_t.size() == 0) return false; 0116 P = std::move(v_t.back()); 0117 v_t.pop_back(); 0118 return true; 0119 } 0120 //------------------------------------------------------------------------- 0121 // function : push_back 0122 /// @brief Insert one vector at the end of the container 0123 /// @param v_other : vector to insert 0124 /// @return reference to the stack_cnc after the insertion 0125 //------------------------------------------------------------------------- 0126 template<class Allocator2> 0127 stack_cnc &push_back(const std::vector<value_type, Allocator2> &v_other) 0128 { 0129 std::lock_guard < spinlock_t > guard(spl); 0130 for (size_type i = 0; i < v_other.size(); ++i) 0131 { 0132 v_t.push_back(v_other[i]); 0133 } 0134 return *this; 0135 } 0136 }; 0137 // end class stack_cnc 0138 0139 //*************************************************************************** 0140 };// end namespace common 0141 };// end namespace sort 0142 };// end namespace boost 0143 //*************************************************************************** 0144 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |