123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- #ifndef __BOOST_SORT_PARALLEL_DETAIL_UTIL_STACK_CNC_HPP
- #define __BOOST_SORT_PARALLEL_DETAIL_UTIL_STACK_CNC_HPP
- #include <ciso646>
- #include <vector>
- #include <boost/sort/common/spinlock.hpp>
- namespace boost
- {
- namespace sort
- {
- namespace common
- {
- template<typename T, typename Allocator = std::allocator<T> >
- class stack_cnc
- {
- public:
-
-
-
- typedef std::vector<T, Allocator> vector_t;
- typedef typename vector_t::size_type size_type;
- typedef typename vector_t::difference_type difference_type;
- typedef typename vector_t::value_type value_type;
- typedef typename vector_t::pointer pointer;
- typedef typename vector_t::const_pointer const_pointer;
- typedef typename vector_t::reference reference;
- typedef typename vector_t::const_reference const_reference;
- typedef typename vector_t::allocator_type allocator_type;
- typedef Allocator alloc_t;
- protected:
-
-
-
- vector_t v_t;
- mutable spinlock_t spl;
- public:
-
-
-
-
-
- explicit stack_cnc(void): v_t() { };
-
-
-
-
-
- stack_cnc(stack_cnc &&) = delete;
-
-
-
-
-
- virtual ~stack_cnc(void) { v_t.clear(); };
-
-
-
-
-
-
- template<class ... Args>
- void emplace_back(Args &&... args)
- {
- std::lock_guard < spinlock_t > guard(spl);
- v_t.emplace_back(std::forward< Args > (args)...);
- }
-
-
-
-
-
-
-
-
- bool pop_move_back(value_type &P)
- {
- std::lock_guard < spinlock_t > S(spl);
- if (v_t.size() == 0) return false;
- P = std::move(v_t.back());
- v_t.pop_back();
- return true;
- }
-
-
-
-
-
-
- template<class Allocator2>
- stack_cnc &push_back(const std::vector<value_type, Allocator2> &v_other)
- {
- std::lock_guard < spinlock_t > guard(spl);
- for (size_type i = 0; i < v_other.size(); ++i)
- {
- v_t.push_back(v_other[i]);
- }
- return *this;
- }
- };
- };
- };
- };
- #endif
|