diff --git a/lib/miniaudio/build.zig b/lib/miniaudio/build.zig index fd967f9..a4b98b5 100644 --- a/lib/miniaudio/build.zig +++ b/lib/miniaudio/build.zig @@ -5,16 +5,14 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - const miniaudio_c = if (static_build or true) b.addStaticLibrary(.{ + const miniaudio_c = b.addLibrary(.{ .name = "miniaudio_c", - .target = target, - .optimize = optimize, - .link_libc = true, - }) else b.addSharedLibrary(.{ - .name = "miniaudio_c", - .target = target, - .optimize = optimize, - .link_libc = true, + .linkage = if (static_build) .static else .dynamic, + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .link_libc = true, + }), }); b.installArtifact(miniaudio_c); @@ -29,10 +27,12 @@ pub fn build(b: *std.Build) void { // ======== tests ============ const test_step = b.step("test", ""); const tests = b.addTest(.{ - .target = target, - .optimize = optimize, - .root_source_file = b.path("src/miniaudio.zig"), - .link_libc = true, + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .root_source_file = b.path("src/miniaudio-test.zig"), + .link_libc = true, + }), }); tests.addIncludePath(b.path("./include")); diff --git a/lib/miniaudio/src/miniaudio.zig b/lib/miniaudio/src/miniaudio.zig index 119be27..f8cadb9 100644 --- a/lib/miniaudio/src/miniaudio.zig +++ b/lib/miniaudio/src/miniaudio.zig @@ -1,17 +1,3 @@ -pub usingnamespace @cImport({ +pub const c = @cImport({ @cInclude("miniaudio.h"); }); - -const c = @This(); -const std = @import("std"); - -test "miniaudio-compile-check" { - try std.testing.expect(c.MA_VERSION_MAJOR == 0); - try std.testing.expect(c.MA_VERSION_MINOR == 11); - - var engine: c.ma_engine = undefined; - const result = c.ma_engine_init(null, &engine); - c.ma_engine_uninit(&engine); - - try std.testing.expect(result == c.MA_SUCCESS); -} diff --git a/lib/nfd/build.zig b/lib/nfd/build.zig index 4316b30..b4e1b17 100644 --- a/lib/nfd/build.zig +++ b/lib/nfd/build.zig @@ -54,10 +54,12 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", ""); const tests = b.addTest(.{ - .target = target, - .optimize = optimize, - .root_source_file = b.path("src/nfd.zig"), - .link_libc = true, + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .root_source_file = b.path("src/nfd.zig"), + .link_libc = true, + }), }); tests.addIncludePath(b.path("./include")); diff --git a/lib/p2/build.zig b/lib/p2/build.zig index adc6202..26a3090 100644 --- a/lib/p2/build.zig +++ b/lib/p2/build.zig @@ -14,9 +14,11 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "test p2"); const tests = b.addTest(.{ - .target = target, - .optimize = optimize, - .root_source_file = b.path("src/p2.zig"), + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .root_source_file = b.path("src/p2.zig"), + }), // .link_libc = true, }); diff --git a/lib/p2/src/p2.zig b/lib/p2/src/p2.zig index 3e6b99b..17c5e0a 100644 --- a/lib/p2/src/p2.zig +++ b/lib/p2/src/p2.zig @@ -17,7 +17,9 @@ pub const xxdWrite = xxd.xxdWrite; pub const loadFileAlloc = utils.loadFileAlloc; const ArrayList = std.ArrayList; const ArrayListUnmanaged = std.ArrayListUnmanaged; -pub usingnamespace @import("structures/interface.zig"); +pub const interface = @import("structures/interface.zig"); +pub const Reference = interface.Reference; +pub const refFromPtr = interface.refFromPtr; pub const assertf = utils.assertf; pub const asserts = utils.asserts; @@ -327,13 +329,13 @@ test "spin child process echo" { std.debug.print("spin child process\n", .{}); const process = try shell.ShellProcess.init(std.testing.allocator, &.{ "echo", "lmao 2 nova" }); defer process.deinit(); - std.debug.print("child process created: {s}\n", .{process.argv}); + std.debug.print("child process created: {any}\n", .{process.argv}); } { std.debug.print("spin child process 2\n", .{}); const process = try shell.ShellProcess.initCmd(std.testing.allocator, "echo lmao2nova -target='lmao 3 nova'"); defer process.deinit(); - std.debug.print("{s}\n", .{process.argv}); + std.debug.print("{any}\n", .{process.argv}); } } diff --git a/lib/p2/src/structures/concurrent-queue.zig b/lib/p2/src/structures/concurrent-queue.zig index bc643a1..bceb285 100644 --- a/lib/p2/src/structures/concurrent-queue.zig +++ b/lib/p2/src/structures/concurrent-queue.zig @@ -50,6 +50,8 @@ pub fn ConcurrentQueueUnmanagedAdvanced(comptime T: type, comptime opts: struct return new; } + // there is 100% an ABA problem going on here... + pub fn push(self: *@This(), value: T) !void { // seek the next unread bit and reserve it const start: usize = self.tail.load(.acquire); @@ -75,10 +77,8 @@ pub fn ConcurrentQueueUnmanagedAdvanced(comptime T: type, comptime opts: struct // this is ok, update our expected value an try to CAS again if ((expected > tail) or ((expected < tail) and expected < self.head.load(.acquire))) { expected = tail; - } - - // something else reserved a slot past ours, we can expect them to fixup the value - if ((tail > expected) or ((tail < expected) and tail < self.head.load(.acquire))) { + } else if ((tail > expected) or ((tail < expected) and tail < self.head.load(.acquire))) { + // something else reserved a slot past ours, we can expect them to fixup the value break; } } @@ -102,6 +102,7 @@ pub fn ConcurrentQueueUnmanagedAdvanced(comptime T: type, comptime opts: struct } } + // newHead = (popIndex + 1) % self.data.len; // spin and resolve while (self.head.cmpxchgStrong(expected, newHead, .seq_cst, .acquire)) |head| { // we failed to increment the head @@ -212,11 +213,10 @@ test "concurrent queue multiple producer single consumer" { .x = id + pushedCount, }) catch unreachable; pushedCount += 1; - std.Thread.sleep(1000 * 1000 * 100); } - _ = pushedCountResults.fetchAdd(pushedCount, .acq_rel); + _ = pushedCountResults.fetchAdd(pushedCount, .seq_cst); } }; @@ -241,23 +241,22 @@ test "concurrent queue multiple producer single consumer" { var poppedCount: i64 = 0; + var signaled: bool = false; + while (timeLeft > 0 or testQueue.count() > 0) { const newTime = test_getTime(); const deltaTime = newTime - oldTime; - if (timeLeft - deltaTime < 5.0) { - exitSignalAtomic.store(true, .release); + + if (timeLeft - deltaTime < 5.0 and !signaled) { + signaled = true; + exitSignalAtomic.store(true, .seq_cst); } + timeLeft -= deltaTime; oldTime = newTime; - - //while (testQueue.pop()) |x| { - { - if (testQueue.pop()) |x| { - _ = x; - // std.debug.print("{d:5} head={d} ", .{ x.x, testQueue.head.load(.acquire) }); - poppedCount += 1; - std.debug.print("popped: {d}\t time left = {d:2.3}\t queueCount = {d} \r", .{ poppedCount, timeLeft, testQueue.count() }); - } + if (testQueue.pop()) |x| { + _ = x; + poppedCount += 1; } std.Thread.sleep(1000 * 1000); } diff --git a/lib/p2/src/structures/string-pool.zig b/lib/p2/src/structures/string-pool.zig index 3eafda8..5e1c4ce 100644 --- a/lib/p2/src/structures/string-pool.zig +++ b/lib/p2/src/structures/string-pool.zig @@ -168,7 +168,7 @@ const Bucket = struct { fn addPage(self: *@This(), allocator: std.mem.Allocator) !void { const page: Page = .{ - .bytes = try allocator.alignedAlloc(u8, 8, self.pageSize), + .bytes = try allocator.alignedAlloc(u8, .@"8", self.pageSize), }; try self.pages.append(allocator, page); } diff --git a/lib/p2/src/utils/shell.zig b/lib/p2/src/utils/shell.zig index 96fcbd5..2c9bb33 100644 --- a/lib/p2/src/utils/shell.zig +++ b/lib/p2/src/utils/shell.zig @@ -9,7 +9,6 @@ pub const ShellProcess = struct { argv: []const []const u8 = undefined, ownedArgs: ?[][]u8 = null, stringArena: p2.BumpArena = undefined, - outputQueue: std.DoublyLinkedList([]const u8) = undefined, // initialize the shellprocess from a windows cmd string pub fn initCmd(alloc: std.mem.Allocator, cmd: []const u8) !*@This() { @@ -41,33 +40,33 @@ pub const ShellProcess = struct { } pub fn splitArgsFromCmd(self: *@This(), cmd: []const u8) !void { - var currentCmd = std.ArrayList(u8).init(self.allocator()); - var ownedArgs = std.ArrayList([]u8).init(self.allocator()); - var terminalStack = std.ArrayList(u8).init(self.backingAllocator); - defer terminalStack.deinit(); + var currentCmd = std.ArrayList(u8){}; + var ownedArgs = std.ArrayList([]u8){}; + var terminalStack = std.ArrayList(u8){}; + defer terminalStack.deinit(self.backingAllocator); for (cmd) |c| { if (terminalStack.items.len == 0) { if (c == ' ') { - try ownedArgs.append(try currentCmd.toOwnedSlice()); + try ownedArgs.append(self.allocator(), try currentCmd.toOwnedSlice(self.allocator())); } else if (c == '\'' or c == '\"') { - try terminalStack.append(c); - try currentCmd.append(c); + try terminalStack.append(self.backingAllocator, c); + try currentCmd.append(self.allocator(), c); } else { - try currentCmd.append(c); + try currentCmd.append(self.allocator(), c); } } else { if (terminalStack.items[terminalStack.items.len - 1] == c) { - try currentCmd.append(terminalStack.pop().?); + try currentCmd.append(self.allocator(), terminalStack.pop().?); } else { - try currentCmd.append(c); + try currentCmd.append(self.allocator(), c); } } } - try ownedArgs.append(try currentCmd.toOwnedSlice()); + try ownedArgs.append(self.allocator(), try currentCmd.toOwnedSlice(self.allocator())); - self.ownedArgs = try ownedArgs.toOwnedSlice(); + self.ownedArgs = try ownedArgs.toOwnedSlice(self.allocator()); self.argv = @ptrCast(self.ownedArgs.?); }