refactor Queue, len check, memory pool for Node of Job, not job

This commit is contained in:
Muaz Ahmad 2023-11-27 13:27:43 +05:00
parent d4194c501c
commit c63d0520c7

View file

@ -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,