yat  0.21pre
Queue.h
1 #ifndef theplu_yat_utility_queue
2 #define theplu_yat_utility_queue
3 
4 // $Id: Queue.h 3999 2020-10-08 23:22:32Z peter $
5 //
6 // Copyright (C) 2013, 2014, 2016, 2017, 2018, 2020 Peter Johansson
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with yat. If not, see <http://www.gnu.org/licenses/>.
20 
21 #include "BasicQueue.h"
22 #include "utility.h"
23 #include "yat_assert.h"
24 
25 #include <deque>
26 #include <mutex>
27 #include <utility>
28 
29 namespace theplu {
30 namespace yat {
31 namespace utility {
32 
57  template<typename T>
58  class Queue :
59  public detail::BasicQueue<Queue<T>, T, std::deque<T> >
60  {
61  friend class detail::BasicQueue<Queue<T>, T, std::deque<T> >;
62  typedef detail::BasicQueue<Queue<T>, T, std::deque<T> > Base;
63  public:
67  Queue(void) {}
68 
72  Queue(const Queue& other)
73  : Base(other) {}
74 
78  Queue& operator=(const Queue& lhs)
79  {
80  this->assign(lhs);
81  return *this;
82  }
83 
84  private:
85  void pop_impl(T& value, std::unique_lock<std::mutex>& lock)
86  {
87  YAT_ASSERT(this->q_.size());
88  value = std::move_if_noexcept(this->q_.front());
89  this->q_.pop_front();
90  }
91 
92 
93  void push_impl(const T& value, std::unique_lock<std::mutex>& lock)
94  {
95  this->q_.push_back(value);
96  }
97 
98 
99  void push_impl(T&& value, std::unique_lock<std::mutex>& lock)
100  {
101  this->q_.push_back(std::move(value));
102  }
103  };
104 
105 }}}
106 #endif
The Department of Theoretical Physics namespace as we define it.
Some useful functions are placed here.
Definition: stl_utility.h:64
Multi-thread safe queue.
Definition: Queue.h:58
void assign(const BasicQueue &other)
Definition: BasicQueue.h:256
Queue(const Queue &other)
Copy constructor.
Definition: Queue.h:72
Definition: BasicQueue.h:36
Queue & operator=(const Queue &lhs)
assignment operator
Definition: Queue.h:78

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14