add atomic to keep track of processed blocks for eof sync

This commit is contained in:
Muaz Ahmad 2023-11-27 16:45:47 +05:00
parent 00637026ea
commit f8847be2fb

View file

@ -1,17 +1,21 @@
const std = @import("std"); const std = @import("std");
const util = @import("util.zig"); const util = @import("util.zig");
const transform = @import("transform.zig");
const AtomicBool = std.atomic.Atomic(bool); const AtomicBool = std.atomic.Atomic(bool);
const AtomicU32 = std.atomic.Atomic(u32);
const Signals = struct { const Signals = struct {
quit: AtomicBool, quit: AtomicBool,
processed: AtomicU32,
const Self = @This(); const Self = @This();
fn init() Self { fn init() Self {
return Self{ return Self{
.quit = AtomicBool.init(false), .quit = AtomicBool.init(false),
.processed = AtomicU32.init(0),
}; };
} }
}; };
@ -70,6 +74,7 @@ pub const ThreadManager = struct {
fn quantize_loop(queue: *util.JobQueue, signals: *Signals) void { fn quantize_loop(queue: *util.JobQueue, signals: *Signals) void {
while (queue.HasJobs() or !signals.quit.load(std.builtin.AtomicOrder.Acquire)) : (std.time.sleep(1)) { while (queue.HasJobs() or !signals.quit.load(std.builtin.AtomicOrder.Acquire)) : (std.time.sleep(1)) {
const job = queue.pop() orelse continue; const job = queue.pop() orelse continue;
std.debug.print("{any}\n", .{job.source.*}); transform.quantize(job.source, job.target);
_ = @atomicRmw(u32, &signals.processed.value, .Add, 1, .SeqCst);
} }
} }