summaryrefslogtreecommitdiff
path: root/src/threads/Workers.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2024-02-22 17:32:27 +0100
committerJörg Frings-Fürst <debian@jff.email>2024-02-22 17:32:27 +0100
commit2bb26608f735b6fc90c06a56793e1cf6e164830a (patch)
tree0b7ca7dcaaeb737b7e539ce4c3992d18c6949370 /src/threads/Workers.vala
parent5c6c59a0325c2f3cc611b8186ac289d011c14369 (diff)
parent5303f650e34763817d7eeb1d3ba774bdec3e1a38 (diff)
Update upstream source from tag 'upstream/0.32.6'
Update to upstream version '0.32.6' with Debian dir 5219d541f047c3ea70dcf1edb7897dd0a7dedfb1
Diffstat (limited to 'src/threads/Workers.vala')
-rw-r--r--src/threads/Workers.vala22
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();