template_queue.h
Go to the documentation of this file.
1 #ifndef TEMPLATE_QUEUE_H
2 #define TEMPLATE_QUEUE_H
3 #include <queue>
4 #include <boost/thread.hpp>
5 #include <boost/chrono.hpp>
6 #include <boost/thread.hpp>
7 #include <boost/chrono.hpp>
8 #include <iostream>
9 template <typename T>
10 class Queue
11 {
12 public:
13 
20  {
21  int retVal = 0;
22  boost::mutex::scoped_lock mlock(mutex_);
23  retVal = queue_.size();
24  return(retVal);
25  }
26 
27 
28 
29  bool isQueueEmpty()
30  {
31  bool retVal = false;
32  boost::mutex::scoped_lock mlock(mutex_);
33  retVal = queue_.empty();
34  return(retVal);
35  }
36 
37  bool waitForIncomingObject(int timeOutInMs)
38  {
39  boost::mutex::scoped_lock mlock(mutex_);
40  bool ret = true;
41  boost::posix_time::time_duration td = boost::posix_time::millisec(timeOutInMs);
42  while (queue_.empty() && (ret == true))
43  {
44  ret = cond_.timed_wait(mlock, td);
45  }
46  return(ret);
47  }
48 
49  T pop()
50  {
51  boost::mutex::scoped_lock mlock(mutex_);
52  while (queue_.empty())
53  {
54  cond_.wait(mlock);
55  }
56  T item = queue_.front();
57  queue_.pop();
58  return item;
59  }
60 
61  void pop(T& item)
62  {
63  boost::mutex::scoped_lock mlock(mutex_);
64  while (queue_.empty())
65  {
66  cond_.wait(mlock);
67  }
68  item = queue_.front();
69  queue_.pop();
70  }
71 
72  void push(const T& item)
73  {
74  boost::mutex::scoped_lock mlock(mutex_);
75  queue_.push(item);
76  mlock.unlock();
77  cond_.notify_one();
78  }
79 
80  void push(T& item)
81  {
82  boost::mutex::scoped_lock mlock(mutex_);
83  queue_.push(item);
84  mlock.unlock();
85  cond_.notify_one();
86  }
87 
88 private:
89  std::queue<T> queue_;
90  boost::mutex mutex_;
92  };
93 #endif
void push(T &item)
void wait(unique_lock< mutex > &m)
std::queue< T > queue_
boost::condition_variable cond_
bool waitForIncomingObject(int timeOutInMs)
bool isQueueEmpty()
void pop(T &item)
void push(const T &item)
boost::mutex mutex_
void notify_one() BOOST_NOEXCEPT
int getNumberOfEntriesInQueue()
get number of entries in queue


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Tue Jul 9 2019 04:55:32