From: Joel Rosdahl Date: Mon, 27 Oct 2025 20:49:02 +0000 (+0100) Subject: refactor: Improve ThreadPool variable names X-Git-Tag: v4.13~89 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=47109b86d6a6f7e1aeede4e93dbbc7e92bbbd4e9;p=thirdparty%2Fccache.git refactor: Improve ThreadPool variable names --- diff --git a/src/ccache/util/threadpool.cpp b/src/ccache/util/threadpool.cpp index ab3ddd20..fc645ce5 100644 --- a/src/ccache/util/threadpool.cpp +++ b/src/ccache/util/threadpool.cpp @@ -45,7 +45,7 @@ ThreadPool::enqueue(std::function function) { std::unique_lock lock(m_mutex); if (!m_shutting_down && m_task_queue.size() >= m_task_queue_max_size) { - m_task_popped_condition.wait(lock, [this] { + m_producer_cv.wait(lock, [this] { return m_shutting_down || m_task_queue.size() < m_task_queue_max_size; }); } @@ -54,7 +54,7 @@ ThreadPool::enqueue(std::function function) } m_task_queue.emplace(std::move(function)); } - m_task_enqueued_or_shutting_down_condition.notify_one(); + m_worker_cv.notify_one(); } void @@ -68,8 +68,8 @@ ThreadPool::shut_down() noexcept } m_shutting_down = true; } - m_task_enqueued_or_shutting_down_condition.notify_all(); - m_task_popped_condition.notify_all(); + m_worker_cv.notify_all(); + m_producer_cv.notify_all(); for (auto& thread : m_worker_threads) { if (thread.joinable()) { thread.join(); @@ -85,7 +85,7 @@ ThreadPool::worker_thread_main() { std::unique_lock lock(m_mutex); - m_task_enqueued_or_shutting_down_condition.wait( + m_worker_cv.wait( lock, [this] { return m_shutting_down || !m_task_queue.empty(); }); if (m_shutting_down && m_task_queue.empty()) { return; @@ -94,7 +94,7 @@ ThreadPool::worker_thread_main() m_task_queue.pop(); } - m_task_popped_condition.notify_one(); + m_producer_cv.notify_one(); try { task(); } catch (const std::exception& e) { diff --git a/src/ccache/util/threadpool.hpp b/src/ccache/util/threadpool.hpp index 6c046ac6..ecc7fe26 100644 --- a/src/ccache/util/threadpool.hpp +++ b/src/ccache/util/threadpool.hpp @@ -48,8 +48,8 @@ private: size_t m_task_queue_max_size; bool m_shutting_down = false; std::mutex m_mutex; - std::condition_variable m_task_enqueued_or_shutting_down_condition; - std::condition_variable m_task_popped_condition; + std::condition_variable m_worker_cv; + std::condition_variable m_producer_cv; void worker_thread_main(); };