diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2024-03-24 09:24:40 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2024-03-24 09:24:40 +0100 |
commit | 734fc45fc296a4b6cfa303329023c24e026f35df (patch) | |
tree | 30038fff46b2fdf3fde9f20a538993cf2ed23fc8 /src/threads/Workers.vala | |
parent | 14bc7db2e07c5d1ccfb4d723c9dba395e6c93171 (diff) | |
parent | dde66becd94817998e320c7ace72729af7455345 (diff) |
Merge branch 'release/debian/0.36.6-1'debian/0.36.6-1
Diffstat (limited to 'src/threads/Workers.vala')
-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(); |