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  bool work();
18 
19  private:
20  std::shared_ptr<TQueue> spTQueueIn;
21 
22  DELETE_COPY(SubThreadQueueIn);
23  };
24 }
25 
26 
27 
28 
29 
30 // Implementation
31 namespace op
32 {
33  template<typename TDatums, typename TWorker, typename TQueue>
35  const std::shared_ptr<TQueue>& tQueueIn) :
36  SubThread<TDatums, TWorker>{tWorkers},
37  spTQueueIn{tQueueIn}
38  {
39  // spTQueueIn->addPopper();
40  }
41 
42  template<typename TDatums, typename TWorker, typename TQueue>
44  {
45  try
46  {
47  // Pop TDatums
48  if (spTQueueIn->empty())
49  std::this_thread::sleep_for(std::chrono::microseconds{100});
50  TDatums tDatums;
51  bool queueIsRunning = spTQueueIn->tryPop(tDatums);
52  // Check queue not empty
53  if (!queueIsRunning)
54  queueIsRunning = spTQueueIn->isRunning();
55  // Process TDatums
56  const auto workersAreRunning = this->workTWorkers(tDatums, queueIsRunning);
57  // Close queue input if all workers closed
58  if (!workersAreRunning)
59  spTQueueIn->stop();
60  return workersAreRunning;
61  }
62  catch (const std::exception& e)
63  {
64  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
65  spTQueueIn->stop();
66  return false;
67  }
68  }
69 
70  COMPILE_TEMPLATE_DATUM(SubThreadQueueIn);
71 }
72 
73 #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:34
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
spTQueueIn
Definition: subThreadQueueIn.hpp:37
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
Definition: subThreadQueueIn.hpp:12