refactor Queue, len check, memory pool for Node of Job, not job
This commit is contained in:
parent
d4194c501c
commit
c63d0520c7
1 changed files with 11 additions and 3 deletions
14
src/util.zig
14
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,
|
||||
|
|
Loading…
Reference in a new issue