From 2f7afe64f65a06d2bdae49b22a97c8f50675dc04 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Mon, 27 Nov 2023 14:06:31 +0500 Subject: [PATCH] refactors, boiler for looping read --- src/input.zig | 10 ++++++++++ src/main.zig | 8 ++++++-- src/util.zig | 10 +++++----- 3 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 src/input.zig diff --git a/src/input.zig b/src/input.zig new file mode 100644 index 0000000..1e8d12a --- /dev/null +++ b/src/input.zig @@ -0,0 +1,10 @@ +const std = @import("std"); + +const util = @import("util.zig"); +const threads = @import("threads.zig"); + +pub fn main_loop(f: std.fs.File, buffs: util.Buffers, thread_mgr: threads.ThreadManager) !void { + _ = thread_mgr; + _ = buffs; + _ = f; +} diff --git a/src/main.zig b/src/main.zig index c38ca4d..009f410 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2,8 +2,9 @@ const std = @import("std"); const util = @import("util.zig"); const threads = @import("threads.zig"); +const input = @import("input.zig"); -const InitError = error { +const InitError = error{ NotEnoughArgs, InvalidDimension, InvalidQuality, @@ -46,7 +47,7 @@ fn get_opts() !util.Options { defer args.deinit(); _ = args.next(); - return util.Options { + return util.Options{ .width = try get_dim(try next_arg(&args)), .height = try get_dim(try next_arg(&args)), .quality = try get_qual(try next_arg(&args)), @@ -62,4 +63,7 @@ pub fn main() !void { var thread_manager = try threads.ThreadManager.init(std.heap.page_allocator, opts.n_quant_jobs); defer thread_manager.deinit(); + + var f = std.io.getStdIn(); + try input.main_loop(f, buffs, thread_manager); } diff --git a/src/util.zig b/src/util.zig index a03b238..b9c29f5 100644 --- a/src/util.zig +++ b/src/util.zig @@ -17,7 +17,7 @@ pub const Job = struct { }; pub const JobQueue = struct { const List = std.TailQueue(Job); - + mutex: std.Thread.Mutex, queue: List, job_pool: JobPool, @@ -26,7 +26,7 @@ pub const JobQueue = struct { const Node = Self.Node; pub fn init(pool: JobPool) Self { - return Self { + return Self{ .mutex = std.Thread.Mutex{}, .queue = List{}, .job_pool = pool, @@ -60,7 +60,7 @@ pub const JobPool = std.heap.MemoryPool(JobQueue.List.Node); pub const Buffers = struct { arena: std.heap.ArenaAllocator, - + Y: [][][4]Block, U: [][]Block, V: [][]Block, @@ -79,9 +79,9 @@ pub const Buffers = struct { var alloc = arena.allocator(); const block_w = w / 16; const block_h = h / 16; - var buffs = Self { + var buffs = Self{ .arena = arena, - + .Y = try alloc.alloc([][4]Block, block_h), .U = try alloc.alloc([]Block, block_h), .V = try alloc.alloc([]Block, block_h),