diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-05-19 18:42:43 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-05-19 18:42:43 -0400 |
commit | 72053457a045a1eaf9453d464632cee75bc3010a (patch) | |
tree | 6b2ffd61ae114a4211ee5247068022b6b19b0edc | |
parent | 6a15f91a1482ee93e5809f15fbc48f9747ad68ee (diff) | |
download | abaddon-portaudio-72053457a045a1eaf9453d464632cee75bc3010a.tar.gz abaddon-portaudio-72053457a045a1eaf9453d464632cee75bc3010a.zip |
optimize curl worker thread a good amount
-rw-r--r-- | filecache.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/filecache.cpp b/filecache.cpp index eb31360..125f0ec 100644 --- a/filecache.cpp +++ b/filecache.cpp @@ -125,6 +125,10 @@ void FileCacheWorkerThread::stop() { } void FileCacheWorkerThread::loop() { + timeval timeout; + timeout.tv_sec = 1; + timeout.tv_usec = 0; + while (!m_stop) { if (m_handles.size() == 0) { std::unique_lock<std::mutex> lock(m_queue_mutex); @@ -133,7 +137,8 @@ void FileCacheWorkerThread::loop() { m_cv.wait(lock); } - if (m_handles.size() < Abaddon::Get().GetSettings().GetCacheHTTPConcurrency()) { + static const auto concurrency = Abaddon::Get().GetSettings().GetCacheHTTPConcurrency(); + if (m_handles.size() < concurrency) { std::optional<QueueEntry> entry; m_queue_mutex.lock(); if (m_queue.size() > 0) { @@ -171,8 +176,20 @@ void FileCacheWorkerThread::loop() { } } - //int fds; - //curl_multi_wait(m_multi_handle, nullptr, 0, 10, &fds); + fd_set fdread; + fd_set fdwrite; + fd_set fdexcep; + int maxfd = -1; + FD_ZERO(&fdread); + FD_ZERO(&fdwrite); + FD_ZERO(&fdexcep); + curl_multi_fdset(m_multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + if (maxfd == -1) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } else { + select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); + } + curl_multi_perform(m_multi_handle, &m_running_handles); int num_msgs; |