MCPcopy Create free account
hub / github.com/CMU-Perceptual-Computing-Lab/openpose / work

Method work

include/openpose/thread/subThreadQueueInOut.hpp:55–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53
54 template<typename TDatums, typename TWorker, typename TQueue>
55 bool SubThreadQueueInOut<TDatums, TWorker, TQueue>::work()
56 {
57 try
58 {
59 // If output queue is closed -> close input queue
60 if (!spTQueueOut->isRunning())
61 {
62 spTQueueIn->stop();
63 return false;
64 }
65 // If output queue running -> normal operation
66 else
67 {
68 // Don't work until next queue is not full
69 // This reduces latency to half
70 if (!spTQueueOut->isFull())
71 {
72 // Pop TDatums
73 if (spTQueueIn->empty())
74 std::this_thread::sleep_for(std::chrono::microseconds{100});
75 TDatums tDatums;
76 bool workersAreRunning = spTQueueIn->tryPop(tDatums);
77 // Check queue not stopped
78 if (!workersAreRunning)
79 workersAreRunning = spTQueueIn->isRunning();
80 // Process TDatums
81 workersAreRunning = this->workTWorkers(tDatums, workersAreRunning);
82 // Push/emplace tDatums if successfully processed
83 if (workersAreRunning)
84 {
85 if (tDatums != nullptr)
86 spTQueueOut->waitAndEmplace(tDatums);
87 }
88 // Close both queues otherwise
89 else
90 {
91 spTQueueIn->stop();
92 spTQueueOut->stopPusher();
93 }
94 return workersAreRunning;
95 }
96 else
97 {
98 std::this_thread::sleep_for(std::chrono::microseconds{100});
99 return true;
100 }
101 }
102 }
103 catch (const std::exception& e)
104 {
105 error(e.what(), __LINE__, __FUNCTION__, __FILE__);
106 spTQueueIn->stop();
107 spTQueueOut->stop();
108 return false;
109 }
110 }
111
112 COMPILE_TEMPLATE_DATUM(SubThreadQueueInOut);

Callers

nothing calls this directly

Calls 10

isFullMethod · 0.80
workTWorkersMethod · 0.80
stopPusherMethod · 0.80
whatMethod · 0.80
errorFunction · 0.50
isRunningMethod · 0.45
stopMethod · 0.45
emptyMethod · 0.45
tryPopMethod · 0.45
waitAndEmplaceMethod · 0.45

Tested by

no test coverage detected