forked from CMU-Perceptual-Computing-Lab/openpose
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubThreadQueueIn.hpp
More file actions
70 lines (57 loc) · 1.99 KB
/
subThreadQueueIn.hpp
File metadata and controls
70 lines (57 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef OPENPOSE_THREAD_THREAD_QUEUE_IN_HPP
#define OPENPOSE_THREAD_THREAD_QUEUE_IN_HPP
#include <openpose/core/common.hpp>
#include <openpose/thread/queue.hpp>
#include <openpose/thread/thread.hpp>
#include <openpose/thread/worker.hpp>
namespace op
{
template<typename TDatums, typename TWorker = std::shared_ptr<Worker<TDatums>>, typename TQueue = Queue<TDatums>>
class SubThreadQueueIn : public SubThread<TDatums, TWorker>
{
public:
SubThreadQueueIn(const std::vector<TWorker>& tWorkers, const std::shared_ptr<TQueue>& tQueueIn);
bool work();
private:
std::shared_ptr<TQueue> spTQueueIn;
DELETE_COPY(SubThreadQueueIn);
};
}
// Implementation
namespace op
{
template<typename TDatums, typename TWorker, typename TQueue>
SubThreadQueueIn<TDatums, TWorker, TQueue>::SubThreadQueueIn(const std::vector<TWorker>& tWorkers, const std::shared_ptr<TQueue>& tQueueIn) :
SubThread<TDatums, TWorker>{tWorkers},
spTQueueIn{tQueueIn}
{
// spTQueueIn->addPopper();
}
template<typename TDatums, typename TWorker, typename TQueue>
bool SubThreadQueueIn<TDatums, TWorker, TQueue>::work()
{
try
{
// Pop TDatums
TDatums tDatums;
bool queueIsRunning = spTQueueIn->tryPop(tDatums);
// Check queue not empty
if (!queueIsRunning)
queueIsRunning = spTQueueIn->isRunning();
// Process TDatums
const auto workersAreRunning = this->workTWorkers(tDatums, queueIsRunning);
// Close queue input if all workers closed
if (!workersAreRunning)
spTQueueIn->stop();
return workersAreRunning;
}
catch (const std::exception& e)
{
error(e.what(), __LINE__, __FUNCTION__, __FILE__);
spTQueueIn->stop();
return false;
}
}
COMPILE_TEMPLATE_DATUM(SubThreadQueueIn);
}
#endif // OPENPOSE_THREAD_THREAD_QUEUE_IN_HPP