]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
perf: Add fast path in ThreadPool::enqueue
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 27 Oct 2025 20:14:40 +0000 (21:14 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 3 Nov 2025 20:03:30 +0000 (21:03 +0100)
src/ccache/util/threadpool.cpp

index 96aabbbe72aae08f5945c85580be41bea5d5c0f0..ab3ddd20661945fda36258e316974a98a4a278a9 100644 (file)
@@ -44,9 +44,11 @@ ThreadPool::enqueue(std::function<void()> function)
 {
   {
     std::unique_lock<std::mutex> lock(m_mutex);
-    m_task_popped_condition.wait(lock, [this] {
-      return m_shutting_down || m_task_queue.size() < m_task_queue_max_size;
-    });
+    if (!m_shutting_down && m_task_queue.size() >= m_task_queue_max_size) {
+      m_task_popped_condition.wait(lock, [this] {
+        return m_shutting_down || m_task_queue.size() < m_task_queue_max_size;
+      });
+    }
     if (m_shutting_down) {
       return;
     }