From a67946de6ce07ba5e8527f095f4dc727e95ce7af Mon Sep 17 00:00:00 2001 From: Aandreba Date: Fri, 10 May 2024 15:49:03 +0200 Subject: [PATCH 1/2] fixed example --- .github/FUNDING.yml | 1 - src/example.zig | 11 ++++------- src/root.zig | 8 ++++---- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index e728538..ada768f 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1 @@ -patreon: paltryorphan96 github: Aandreba diff --git a/src/example.zig b/src/example.zig index d086a59..19b18b8 100644 --- a/src/example.zig +++ b/src/example.zig @@ -27,21 +27,18 @@ test "example" { std.debug.print("Heap align: {}\n\n", .{Arc.innerAlign()}); var value = try Arc.init(std.testing.allocator, .{}); - errdefer value.releaseWithFn(Data.deinit); + errdefer value.releaseWithFn(Data.deinit, .{}); var handles: [THREADS]Thread = undefined; var i: usize = 0; while (i < THREADS) { const this_value = value.retain(); - errdefer this_value.releaseWithFn(Data.deinit); + errdefer this_value.releaseWithFn(Data.deinit, .{}); handles[i] = try Thread.spawn(.{}, thread_exec, .{this_value}); i += 1; } - for (handles) |handle| { - handle.join(); - } - + for (handles) |handle| handle.join(); const owned_value: Data = value.tryUnwrap().?; defer owned_value.deinit(); @@ -49,7 +46,7 @@ test "example" { } fn thread_exec(data: Arc) !void { - defer data.releaseWithFn(Data.deinit); + defer data.releaseWithFn(Data.deinit, .{}); var rng = std.rand.DefaultPrng.init(@as(u64, @bitCast(@as(i64, @truncate(std.time.nanoTimestamp()))))); diff --git a/src/root.zig b/src/root.zig index f8610a1..577dbc6 100644 --- a/src/root.zig +++ b/src/root.zig @@ -85,7 +85,7 @@ pub fn RcAligned(comptime T: type, comptime alignment: ?u29) type { /// Decrements the reference count, deallocating the weak count reaches zero, /// and executing `f` if the strong count reaches zero. - /// The `f` function has a signature of `fn(*T, ...args)` or `fn(T, ...args)` + /// The `f` function has a signature of `fn(*T, ...args)` or `fn(T, ...args)`. /// The continued use of the pointer after calling `release` is undefined behaviour. pub fn releaseWithFn(self: Self, comptime f: anytype, args: anytype) void { return self.asUnmanaged().releaseWithFn(self.alloc, f, args); @@ -291,7 +291,7 @@ pub fn ArcAligned(comptime T: type, comptime alignment: ?u29) type { /// Decrements the reference count, deallocating the weak count reaches zero, /// and executing `f` if the strong count reaches zero. - /// The `f` function has a signature of `fn(*T, ...args)` or `fn(T, ...args)` + /// The `f` function has a signature of `fn(*T, ...args)` or `fn(T, ...args)`. /// The continued use of the pointer after calling `release` is undefined behaviour. pub fn releaseWithFn(self: Self, comptime f: anytype, args: anytype) void { return self.asUnmanaged().releaseWithFn(self.alloc, f, args); @@ -519,7 +519,7 @@ pub fn RcAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) type { /// Decrements the reference count, deallocating the weak count reaches zero, /// and executing `f` if the strong count reaches zero. - /// The `f` function has a signature of `fn(*T, ...args)` or `fn(T, ...args)` + /// The `f` function has a signature of `fn(*T, ...args)` or `fn(T, ...args)`. /// The continued use of the pointer after calling `release` is undefined behaviour. pub fn releaseWithFn(self: Self, allocator: Allocator, comptime f: anytype, args: anytype) void { const ptr = self.innerPtr(); @@ -767,7 +767,7 @@ pub fn ArcAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) type { /// Decrements the reference count, deallocating the weak count reaches zero, /// and executing `f` if the strong count reaches zero. - /// The `f` function has a signature of `fn(*T, ...args)` or `fn(T, ...args)` + /// The `f` function has a signature of `fn(*T, ...args)` or `fn(T, ...args)`. /// The continued use of the pointer after calling `release` is undefined behaviour. pub fn releaseWithFn(self: Self, allocator: Allocator, comptime f: anytype, args: anytype) void { const ptr = self.innerPtr(); From 13012592ee72362869606dea18f5f50e4a2098fc Mon Sep 17 00:00:00 2001 From: Aandreba Date: Fri, 10 May 2024 15:53:51 +0200 Subject: [PATCH 2/2] updated readme example --- README.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3459b18..67e0791 100644 --- a/README.md +++ b/README.md @@ -41,21 +41,18 @@ test "example" { std.debug.print("Heap align: {}\n\n", .{Arc.innerAlign()}); var value = try Arc.init(std.testing.allocator, .{}); - errdefer value.releaseWithFn(Data.deinit); + errdefer value.releaseWithFn(Data.deinit, .{}); var handles: [THREADS]Thread = undefined; var i: usize = 0; while (i < THREADS) { const this_value = value.retain(); - errdefer this_value.releaseWithFn(Data.deinit); + errdefer this_value.releaseWithFn(Data.deinit, .{}); handles[i] = try Thread.spawn(.{}, thread_exec, .{this_value}); i += 1; } - for (handles) |handle| { - handle.join(); - } - + for (handles) |handle| handle.join(); const owned_value: Data = value.tryUnwrap().?; defer owned_value.deinit(); @@ -63,9 +60,9 @@ test "example" { } fn thread_exec(data: Arc) !void { - defer data.releaseWithFn(Data.deinit); + defer data.releaseWithFn(Data.deinit, .{}); - var rng = std.rand.DefaultPrng.init(@bitCast(u64, @truncate(i64, std.time.nanoTimestamp()))); + var rng = std.rand.DefaultPrng.init(@as(u64, @bitCast(@as(i64, @truncate(std.time.nanoTimestamp()))))); data.value.mutex.lock(); defer data.value.mutex.unlock();