yat  0.16.4pre
Queue.h
1 #ifndef theplu_yat_utility_queue
2 #define theplu_yat_utility_queue
3 
4 // $Id: Queue.h 3792 2019-04-12 07:15:09Z peter $
5 //
6 // Copyright (C) 2013, 2014, 2016, 2017, 2018 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 "config_public.h"
22 
23 #include "BasicQueue.h"
24 #include "utility.h"
25 #include "yat_assert.h"
26 
27 #include <boost/thread.hpp>
28 
29 #include <deque>
30 #include <utility>
31 
32 namespace theplu {
33 namespace yat {
34 namespace utility {
35 
60  template<typename T>
61  class Queue :
62  public detail::BasicQueue<Queue<T>, T, std::deque<T> >
63  {
64  friend class detail::BasicQueue<Queue<T>, T, std::deque<T> >;
65  typedef detail::BasicQueue<Queue<T>, T, std::deque<T> > Base;
66  public:
70  Queue(void) {}
71 
75  Queue(const Queue& other)
76  : Base(other) {}
77 
81  Queue& operator=(const Queue& lhs)
82  {
83  this->assign(lhs);
84  return *this;
85  }
86 
87  private:
88  void pop_impl(T& value, boost::unique_lock<boost::mutex>& lock)
89  {
90  YAT_ASSERT(this->q_.size());
91  value = YAT_MOVE_IF_NOEXCEPT(this->q_.front());
92  this->q_.pop_front();
93  }
94 
95 
96  void push_impl(const T& value, boost::unique_lock<boost::mutex>& lock)
97  {
98  this->q_.push_back(value);
99  }
100 
101 
102 #ifdef YAT_HAVE_RVALUE
103  void push_impl(T&& value, boost::unique_lock<boost::mutex>& lock)
104  {
105  this->q_.push_back(std::move(value));
106  }
107 #endif
108  };
109 
110 }}}
111 #endif
The Department of Theoretical Physics namespace as we define it.
Some useful functions are placed here.
Multi-thread safe queue.
Definition: Queue.h:61
void assign(const BasicQueue &other)
Definition: BasicQueue.h:168
Queue(const Queue &other)
Copy constructor.
Definition: Queue.h:75
Definition: BasicQueue.h:34
#define YAT_MOVE_IF_NOEXCEPT(arg)
if rvalue not available, do nothing
Definition: utility.h:352
Queue & operator=(const Queue &lhs)
assignment operator
Definition: Queue.h:81

Generated on Thu Dec 12 2019 03:12:08 for yat by  doxygen 1.8.11