This function blocks the thread until there is a response for one of the id_tasks
| 1767 | |
| 1768 | // This function blocks the thread until there is a response for one of the id_tasks |
| 1769 | server_task_result_ptr recv(const std::unordered_set<int> & id_tasks) { |
| 1770 | while (true) { |
| 1771 | std::unique_lock<std::mutex> lock(mutex_results); |
| 1772 | condition_results.wait(lock, [&]{ |
| 1773 | if (!running) { |
| 1774 | SRV_DBG("%s : queue result stop\n", __func__); |
| 1775 | std::terminate(); // we cannot return here since the caller is HTTP code |
| 1776 | } |
| 1777 | return !queue_results.empty(); |
| 1778 | }); |
| 1779 | |
| 1780 | for (size_t i = 0; i < queue_results.size(); i++) { |
| 1781 | if (id_tasks.find(queue_results[i]->id) != id_tasks.end()) { |
| 1782 | server_task_result_ptr res = std::move(queue_results[i]); |
| 1783 | queue_results.erase(queue_results.begin() + i); |
| 1784 | return res; |
| 1785 | } |
| 1786 | } |
| 1787 | } |
| 1788 | |
| 1789 | // should never reach here |
| 1790 | } |
| 1791 | |
| 1792 | // same as recv(), but have timeout in seconds |
| 1793 | // if timeout is reached, nullptr is returned |