| ... | @@ -223,7 +223,7 @@ pub fn spawn(pool: *Pool, comptime func: anytype, args: anytype) !void { | ... | @@ -223,7 +223,7 @@ pub fn spawn(pool: *Pool, comptime func: anytype, args: anytype) !void { |
| 223 | pool: *Pool, | 223 | pool: *Pool, |
| 224 | run_node: RunQueue.Node = .{ .data = .{ .runFn = runFn } }, | 224 | run_node: RunQueue.Node = .{ .data = .{ .runFn = runFn } }, |
| 225 | | 225 | |
| 226 | fn runFn(runnable: *Runnable) void { | 226 | fn runFn(runnable: *Runnable, _: ?usize) void { |
| 227 | const run_node: *RunQueue.Node = @fieldParentPtr("data", runnable); | 227 | const run_node: *RunQueue.Node = @fieldParentPtr("data", runnable); |
| 228 | const closure: *@This() = @alignCast(@fieldParentPtr("run_node", run_node)); | 228 | const closure: *@This() = @alignCast(@fieldParentPtr("run_node", run_node)); |
| 229 | @call(.auto, func, closure.arguments); | 229 | @call(.auto, func, closure.arguments); |
| ... | @@ -254,6 +254,27 @@ pub fn spawn(pool: *Pool, comptime func: anytype, args: anytype) !void { | ... | @@ -254,6 +254,27 @@ pub fn spawn(pool: *Pool, comptime func: anytype, args: anytype) !void { |
| 254 | pool.cond.signal(); | 254 | pool.cond.signal(); |
| 255 | } | 255 | } |
| 256 | | 256 | |
| | 257 | test spawn { |
| | 258 | const TestFn = struct { |
| | 259 | fn checkRun(completed: *bool) void { |
| | 260 | completed.* = true; |
| | 261 | } |
| | 262 | }; |
| | 263 | |
| | 264 | var completed: bool = false; |
| | 265 | |
| | 266 | { |
| | 267 | var pool: Pool = undefined; |
| | 268 | try pool.init(.{ |
| | 269 | .allocator = std.testing.allocator, |
| | 270 | }); |
| | 271 | defer pool.deinit(); |
| | 272 | try pool.spawn(TestFn.checkRun, .{&completed}); |
| | 273 | } |
| | 274 | |
| | 275 | try std.testing.expectEqual(true, completed); |
| | 276 | } |
| | 277 | |
| 257 | fn worker(pool: *Pool) void { | 278 | fn worker(pool: *Pool) void { |
| 258 | pool.mutex.lock(); | 279 | pool.mutex.lock(); |
| 259 | defer pool.mutex.unlock(); | 280 | defer pool.mutex.unlock(); |