diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2024-02-22 17:32:07 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2024-02-22 17:32:07 +0100 |
commit | 5303f650e34763817d7eeb1d3ba774bdec3e1a38 (patch) | |
tree | 8ad5028940b931abe0eee441e12357f970c656de /src/threads | |
parent | f5a0cee8ccecc7b6c6c2d8e9fb6f6eecd53531fe (diff) |
New upstream version 0.32.6upstream/0.32.6
Diffstat (limited to 'src/threads')
-rw-r--r-- | src/threads/Workers.vala | 22 |
1 files changed, 8 insertions, 14 deletions
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<void *> thread_pool; private AsyncQueue<BackgroundJob> queue = new AsyncQueue<BackgroundJob>(); 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(); |