From 5303f650e34763817d7eeb1d3ba774bdec3e1a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Thu, 22 Feb 2024 17:32:07 +0100 Subject: New upstream version 0.32.6 --- src/threads/Workers.vala | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'src/threads') diff --git a/src/threads/Workers.vala b/src/threads/Workers.vala index 60751a9..42d696c 100644 --- a/src/threads/Workers.vala +++ b/src/threads/Workers.vala @@ -18,7 +18,6 @@ public class Workers { private ThreadPool thread_pool; private AsyncQueue queue = new AsyncQueue(); private EventSemaphore empty_event = new EventSemaphore(); - private int enqueued = 0; public Workers(uint max_threads, bool exclusive) { if (max_threads <= 0 && max_threads != UNLIMITED_THREADS) @@ -51,10 +50,7 @@ public class Workers { public void enqueue(BackgroundJob job) { empty_event.reset(); - lock (queue) { - queue.push_sorted(job, BackgroundJob.priority_compare_func); - enqueued++; - } + queue.push_sorted(job, BackgroundJob.priority_compare_func); try { thread_pool.add(job); @@ -76,21 +72,19 @@ public class Workers { // Returns the number of BackgroundJobs on the queue, not including active jobs. public int get_pending_job_count() { - lock (queue) { - return enqueued; - } + return queue.length(); } private void thread_start(void *ignored) { BackgroundJob? job; bool empty; - lock (queue) { - job = queue.try_pop(); - assert(job != null); + + queue.lock(); + job = queue.try_pop_unlocked(); + assert(job != null); - assert(enqueued > 0); - empty = (--enqueued == 0); - } + empty = queue.length_unlocked() == 0; + queue.unlock(); if (!job.is_cancelled()) job.execute(); -- cgit v1.2.3