]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Improve ThreadPool variable names
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 27 Oct 2025 20:49:02 +0000 (21:49 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 3 Nov 2025 20:03:30 +0000 (21:03 +0100)
src/ccache/util/threadpool.cpp
src/ccache/util/threadpool.hpp

index ab3ddd20661945fda36258e316974a98a4a278a9..fc645ce5f589ac103fbb32567cc4a2479c21d6e4 100644 (file)
@@ -45,7 +45,7 @@ ThreadPool::enqueue(std::function<void()> function)
   {
     std::unique_lock<std::mutex> 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<void()> 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<std::mutex> 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) {
index 6c046ac6d9c0da195b97ce91ff04675b68455d52..ecc7fe261def730a119c977d60a4ff90e2fb54b8 100644 (file)
@@ -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();
 };