From c63d0520c7b00d88b64e2369721fd8f71f1ebbda Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Mon, 27 Nov 2023 13:27:43 +0500 Subject: [PATCH] refactor Queue, len check, memory pool for Node of Job, not job --- src/util.zig | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/util.zig b/src/util.zig index 0364b34..a03b238 100644 --- a/src/util.zig +++ b/src/util.zig @@ -16,8 +16,10 @@ pub const Job = struct { target: *BlockQuantized, }; pub const JobQueue = struct { + const List = std.TailQueue(Job); + mutex: std.Thread.Mutex, - queue: std.TailQueue(Job), + queue: List, job_pool: JobPool, const Self = @This(); @@ -26,7 +28,7 @@ pub const JobQueue = struct { pub fn init(pool: JobPool) Self { return Self { .mutex = std.Thread.Mutex{}, - .queue = std.TailQueue(Job){}, + .queue = List{}, .job_pool = pool, }; } @@ -47,8 +49,14 @@ pub const JobQueue = struct { self.job_pool.destroy(n); return job; } + + pub fn HasJobs(self: *Self) bool { + self.mutex.lock(); + defer self.mutex.unlock(); + return (self.queue.len == 0); + } }; -pub const JobPool = std.heap.MemoryPool(Job); +pub const JobPool = std.heap.MemoryPool(JobQueue.List.Node); pub const Buffers = struct { arena: std.heap.ArenaAllocator,