| 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 | } |
nothing calls this directly
no test coverage detected