| 48 | |
| 49 | template<typename TDatums, typename TWorker, typename TQueue> |
| 50 | bool SubThreadQueueIn<TDatums, TWorker, TQueue>::work() |
| 51 | { |
| 52 | try |
| 53 | { |
| 54 | // Pop TDatums |
| 55 | if (spTQueueIn->empty()) |
| 56 | std::this_thread::sleep_for(std::chrono::microseconds{100}); |
| 57 | TDatums tDatums; |
| 58 | bool queueIsRunning = spTQueueIn->tryPop(tDatums); |
| 59 | // Check queue not empty |
| 60 | if (!queueIsRunning) |
| 61 | queueIsRunning = spTQueueIn->isRunning(); |
| 62 | // Process TDatums |
| 63 | const auto workersAreRunning = this->workTWorkers(tDatums, queueIsRunning); |
| 64 | // Close queue input if all workers closed |
| 65 | if (!workersAreRunning) |
| 66 | spTQueueIn->stop(); |
| 67 | return workersAreRunning; |
| 68 | } |
| 69 | catch (const std::exception& e) |
| 70 | { |
| 71 | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| 72 | spTQueueIn->stop(); |
| 73 | return false; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | COMPILE_TEMPLATE_DATUM(SubThreadQueueIn); |
| 78 | } |