OpenPose 1.0.0rc2 OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
subThreadQueueOut.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_THREAD_THREAD_QUEUE_OUT_HPP
2 #define OPENPOSE_THREAD_THREAD_QUEUE_OUT_HPP
3
4 #include <openpose/core/common.hpp>
5 #include <openpose/thread/queue.hpp>
6 #include <openpose/thread/thread.hpp>
7 #include <openpose/thread/worker.hpp>
8
9 namespace op
10 {
11 template<typename TDatums, typename TWorker = std::shared_ptr<Worker<TDatums>>, typename TQueue = Queue<TDatums>>
12 class SubThreadQueueOut : public SubThread<TDatums, TWorker>
13 {
14 public:
15 SubThreadQueueOut(const std::vector<TWorker>& tWorkers, const std::shared_ptr<TQueue>& tQueueOut);
16
17 virtual ~SubThreadQueueOut();
18
19 bool work();
20
21 private:
22 std::shared_ptr<TQueue> spTQueueOut;
23
24 DELETE_COPY(SubThreadQueueOut);
25 };
26 }
27
28
29
30
31
32 // Implementation
33 namespace op
34 {
35 template<typename TDatums, typename TWorker, typename TQueue>
36 SubThreadQueueOut<TDatums, TWorker, TQueue>::SubThreadQueueOut(const std::vector<TWorker>& tWorkers,
37 const std::shared_ptr<TQueue>& tQueueOut) :
38 SubThread<TDatums, TWorker>{tWorkers},
39 spTQueueOut{tQueueOut}
40 {
41 spTQueueOut->addPusher();
42 }
43
44 template<typename TDatums, typename TWorker, typename TQueue>
45 SubThreadQueueOut<TDatums, TWorker, TQueue>::~SubThreadQueueOut()
46 {
47 }
48
49 template<typename TDatums, typename TWorker, typename TQueue>
50 bool SubThreadQueueOut<TDatums, TWorker, TQueue>::work()
51 {
52 try
53 {
54 // If output queue is closed -> close input queue
55 if (!spTQueueOut->isRunning())
56 return false;
57 else
58 {
59 // Don't work until next queue is not full
60 // This reduces latency to half
61 if (!spTQueueOut->isFull())
62 {
63 // Process TDatums
64 TDatums tDatums;
65 const auto workersAreRunning = this->workTWorkers(tDatums, true);
66 // Push/emplace tDatums if successfully processed
67 if (workersAreRunning)
68 {
69 if (tDatums != nullptr)
70 spTQueueOut->waitAndEmplace(tDatums);
71 }
72 // Close queue otherwise
73 else
74 spTQueueOut->stopPusher();
75 return workersAreRunning;
76 }
77 else
78 {
79 std::this_thread::sleep_for(std::chrono::microseconds{100});
80 return true;
81 }
82 }
83 }
84 catch (const std::exception& e)
85 {
86 error(e.what(), __LINE__, __FUNCTION__, __FILE__);
87 spTQueueOut->stop();
88 return false;
89 }
90 }
91
92 COMPILE_TEMPLATE_DATUM(SubThreadQueueOut);
93 }
94
95 #endif // OPENPOSE_THREAD_THREAD_QUEUE_OUT_HPP
op::SubThreadQueueOut::~SubThreadQueueOut
virtual ~SubThreadQueueOut()
op::SubThread
Definition: subThread.hpp:10
common.hpp
op::error
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
thread.hpp
worker.hpp
op::spTQueueOut
spTQueueOut
Definition: subThreadQueueInOut.hpp:43
op::SubThreadQueueOut
Definition: subThreadQueueOut.hpp:12
op::COMPILE_TEMPLATE_DATUM
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
op::SubThreadQueueOut::SubThreadQueueOut
SubThreadQueueOut(const std::vector< TWorker > &tWorkers, const std::shared_ptr< TQueue > &tQueueOut)
Definition: subThreadQueueOut.hpp:36
queue.hpp
op::SubThreadQueueOut::work
bool work()