OpenPose  1.0.0rc2
OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
subThreadQueueIn.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_THREAD_THREAD_QUEUE_IN_HPP
2 #define OPENPOSE_THREAD_THREAD_QUEUE_IN_HPP
3 
8 
9 namespace op
10 {
11  template<typename TDatums, typename TWorker = std::shared_ptr<Worker<TDatums>>, typename TQueue = Queue<TDatums>>
12  class SubThreadQueueIn : public SubThread<TDatums, TWorker>
13  {
14  public:
15  SubThreadQueueIn(const std::vector<TWorker>& tWorkers, const std::shared_ptr<TQueue>& tQueueIn);
16 
17  virtual ~SubThreadQueueIn();
18 
19  bool work();
20 
21  private:
22  std::shared_ptr<TQueue> spTQueueIn;
23 
24  DELETE_COPY(SubThreadQueueIn);
25  };
26 }
27 
28 
29 
30 
31 
32 // Implementation
33 namespace op
34 {
35  template<typename TDatums, typename TWorker, typename TQueue>
37  const std::shared_ptr<TQueue>& tQueueIn) :
38  SubThread<TDatums, TWorker>{tWorkers},
39  spTQueueIn{tQueueIn}
40  {
41  // spTQueueIn->addPopper();
42  }
43 
44  template<typename TDatums, typename TWorker, typename TQueue>
46  {
47  }
48 
49  template<typename TDatums, typename TWorker, typename TQueue>
51  {
52  try
53  {
54  // Pop TDatums
55  if (spTQueueIn->empty())
56  std::this_thread::sleep_for(std::chrono::microseconds{100});
57  TDatums tDatums;
58  bool queueIsRunning = spTQueueIn->tryPop(tDatums);
59  // Check queue not empty
60  if (!queueIsRunning)
61  queueIsRunning = spTQueueIn->isRunning();
62  // Process TDatums
63  const auto workersAreRunning = this->workTWorkers(tDatums, queueIsRunning);
64  // Close queue input if all workers closed
65  if (!workersAreRunning)
66  spTQueueIn->stop();
67  return workersAreRunning;
68  }
69  catch (const std::exception& e)
70  {
71  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
72  spTQueueIn->stop();
73  return false;
74  }
75  }
76 
77  COMPILE_TEMPLATE_DATUM(SubThreadQueueIn);
78 }
79 
80 #endif // OPENPOSE_THREAD_THREAD_QUEUE_IN_HPP
Definition: subThread.hpp:10
SubThreadQueueIn(const std::vector< TWorker > &tWorkers, const std::shared_ptr< TQueue > &tQueueIn)
Definition: subThreadQueueIn.hpp:36
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
spTQueueIn
Definition: subThreadQueueIn.hpp:39
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
virtual ~SubThreadQueueIn()
Definition: subThreadQueueIn.hpp:12