Optimise : use condition variable instead of unreliable wait
This commit is contained in:
parent
93dd64ceca
commit
bed536309e
1 changed files with 8 additions and 1 deletions
|
@ -806,6 +806,8 @@ CURLM* curl_multi_handle;
|
||||||
std::map<CURLM*, CURLcode> curl_handles_done;
|
std::map<CURLM*, CURLcode> curl_handles_done;
|
||||||
std::condition_variable on_done;
|
std::condition_variable on_done;
|
||||||
std::mutex handles_done_m;
|
std::mutex handles_done_m;
|
||||||
|
std::condition_variable on_req_added;
|
||||||
|
std::mutex req_added_m;
|
||||||
Thread curl_multi_loop_thread;
|
Thread curl_multi_loop_thread;
|
||||||
|
|
||||||
[[noreturn]] void curl_multi_loop(void* p) {
|
[[noreturn]] void curl_multi_loop(void* p) {
|
||||||
|
@ -825,7 +827,10 @@ Thread curl_multi_loop_thread;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!openHandles) {
|
if (!openHandles) {
|
||||||
svcSleepThread((u64)1000000ULL * 100);
|
std::unique_lock lk(req_added_m);
|
||||||
|
on_req_added.wait(lk);
|
||||||
|
}else {
|
||||||
|
curl_multi_poll(curl_multi_handle, nullptr, 0, 5000, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -878,6 +883,8 @@ json_t* Client::doRequestCurl(const char* method, const std::string& url, json_t
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
|
||||||
|
|
||||||
curl_multi_add_handle(curl_multi_handle, curl);
|
curl_multi_add_handle(curl_multi_handle, curl);
|
||||||
|
curl_multi_wakeup(curl_multi_handle);
|
||||||
|
on_req_added.notify_one(); // There is only one thread processing that
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
{
|
{
|
||||||
std::unique_lock lk(handles_done_m);
|
std::unique_lock lk(handles_done_m);
|
||||||
|
|
Loading…
Reference in a new issue