refactors, boiler for looping read

This commit is contained in:
Muaz Ahmad 2023-11-27 14:06:31 +05:00
parent 18a998e737
commit 2f7afe64f6
3 changed files with 21 additions and 7 deletions

10
src/input.zig Normal file
View file

@ -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;
}

View file

@ -2,8 +2,9 @@ const std = @import("std");
const util = @import("util.zig"); const util = @import("util.zig");
const threads = @import("threads.zig"); const threads = @import("threads.zig");
const input = @import("input.zig");
const InitError = error { const InitError = error{
NotEnoughArgs, NotEnoughArgs,
InvalidDimension, InvalidDimension,
InvalidQuality, InvalidQuality,
@ -46,7 +47,7 @@ fn get_opts() !util.Options {
defer args.deinit(); defer args.deinit();
_ = args.next(); _ = args.next();
return util.Options { return util.Options{
.width = try get_dim(try next_arg(&args)), .width = try get_dim(try next_arg(&args)),
.height = try get_dim(try next_arg(&args)), .height = try get_dim(try next_arg(&args)),
.quality = try get_qual(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); var thread_manager = try threads.ThreadManager.init(std.heap.page_allocator, opts.n_quant_jobs);
defer thread_manager.deinit(); defer thread_manager.deinit();
var f = std.io.getStdIn();
try input.main_loop(f, buffs, thread_manager);
} }

View file

@ -17,7 +17,7 @@ pub const Job = struct {
}; };
pub const JobQueue = struct { pub const JobQueue = struct {
const List = std.TailQueue(Job); const List = std.TailQueue(Job);
mutex: std.Thread.Mutex, mutex: std.Thread.Mutex,
queue: List, queue: List,
job_pool: JobPool, job_pool: JobPool,
@ -26,7 +26,7 @@ pub const JobQueue = struct {
const Node = Self.Node; const Node = Self.Node;
pub fn init(pool: JobPool) Self { pub fn init(pool: JobPool) Self {
return Self { return Self{
.mutex = std.Thread.Mutex{}, .mutex = std.Thread.Mutex{},
.queue = List{}, .queue = List{},
.job_pool = pool, .job_pool = pool,
@ -60,7 +60,7 @@ pub const JobPool = std.heap.MemoryPool(JobQueue.List.Node);
pub const Buffers = struct { pub const Buffers = struct {
arena: std.heap.ArenaAllocator, arena: std.heap.ArenaAllocator,
Y: [][][4]Block, Y: [][][4]Block,
U: [][]Block, U: [][]Block,
V: [][]Block, V: [][]Block,
@ -79,9 +79,9 @@ pub const Buffers = struct {
var alloc = arena.allocator(); var alloc = arena.allocator();
const block_w = w / 16; const block_w = w / 16;
const block_h = h / 16; const block_h = h / 16;
var buffs = Self { var buffs = Self{
.arena = arena, .arena = arena,
.Y = try alloc.alloc([][4]Block, block_h), .Y = try alloc.alloc([][4]Block, block_h),
.U = try alloc.alloc([]Block, block_h), .U = try alloc.alloc([]Block, block_h),
.V = try alloc.alloc([]Block, block_h), .V = try alloc.alloc([]Block, block_h),