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,