MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / recv

Method recv

smallthinker/tools/server/server.cpp:1769–1790  ·  view source on GitHub ↗

This function blocks the thread until there is a response for one of the id_tasks

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.80

Calls 6

findMethod · 0.80
waitMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected