| ... | ... | @@ -97,7 +97,7 @@ pub fn spawnWg(pool: *Pool, wait_group: *WaitGroup, comptime func: anytype, args |
| 97 | 97 | wait_group.start(); |
| 98 | 98 | |
| 99 | 99 | if (builtin.single_threaded) { |
| 100 | | callFn(func, args); |
| 100 | @call(.auto, func, args); |
| 101 | 101 | wait_group.finish(); |
| 102 | 102 | return; |
| 103 | 103 | } |
| ... | ... | @@ -112,7 +112,7 @@ pub fn spawnWg(pool: *Pool, wait_group: *WaitGroup, comptime func: anytype, args |
| 112 | 112 | fn runFn(runnable: *Runnable, _: ?usize) void { |
| 113 | 113 | const run_node: *RunQueue.Node = @fieldParentPtr("data", runnable); |
| 114 | 114 | const closure: *@This() = @alignCast(@fieldParentPtr("run_node", run_node)); |
| 115 | | callFn(func, closure.arguments); |
| 115 | @call(.auto, func, closure.arguments); |
| 116 | 116 | closure.wait_group.finish(); |
| 117 | 117 | |
| 118 | 118 | // The thread pool's allocator is protected by the mutex. |
| ... | ... | @@ -129,7 +129,7 @@ pub fn spawnWg(pool: *Pool, wait_group: *WaitGroup, comptime func: anytype, args |
| 129 | 129 | |
| 130 | 130 | const closure = pool.allocator.create(Closure) catch { |
| 131 | 131 | pool.mutex.unlock(); |
| 132 | | callFn(func, args); |
| 132 | @call(.auto, func, args); |
| 133 | 133 | wait_group.finish(); |
| 134 | 134 | return; |
| 135 | 135 | }; |
| ... | ... | @@ -160,7 +160,7 @@ pub fn spawnWgId(pool: *Pool, wait_group: *WaitGroup, comptime func: anytype, ar |
| 160 | 160 | wait_group.start(); |
| 161 | 161 | |
| 162 | 162 | if (builtin.single_threaded) { |
| 163 | | callFn(func, .{0} ++ args); |
| 163 | @call(.auto, func, .{0} ++ args); |
| 164 | 164 | wait_group.finish(); |
| 165 | 165 | return; |
| 166 | 166 | } |
| ... | ... | @@ -175,7 +175,7 @@ pub fn spawnWgId(pool: *Pool, wait_group: *WaitGroup, comptime func: anytype, ar |
| 175 | 175 | fn runFn(runnable: *Runnable, id: ?usize) void { |
| 176 | 176 | const run_node: *RunQueue.Node = @fieldParentPtr("data", runnable); |
| 177 | 177 | const closure: *@This() = @alignCast(@fieldParentPtr("run_node", run_node)); |
| 178 | | callFn(func, .{id.?} ++ closure.arguments); |
| 178 | @call(.auto, func, .{id.?} ++ closure.arguments); |
| 179 | 179 | closure.wait_group.finish(); |
| 180 | 180 | |
| 181 | 181 | // The thread pool's allocator is protected by the mutex. |
| ... | ... | @@ -193,7 +193,7 @@ pub fn spawnWgId(pool: *Pool, wait_group: *WaitGroup, comptime func: anytype, ar |
| 193 | 193 | const closure = pool.allocator.create(Closure) catch { |
| 194 | 194 | const id: ?usize = pool.ids.getIndex(std.Thread.getCurrentId()); |
| 195 | 195 | pool.mutex.unlock(); |
| 196 | | callFn(func, .{id.?} ++ args); |
| 196 | @call(.auto, func, .{id.?} ++ args); |
| 197 | 197 | wait_group.finish(); |
| 198 | 198 | return; |
| 199 | 199 | }; |
| ... | ... | @@ -213,7 +213,7 @@ pub fn spawnWgId(pool: *Pool, wait_group: *WaitGroup, comptime func: anytype, ar |
| 213 | 213 | |
| 214 | 214 | pub fn spawn(pool: *Pool, comptime func: anytype, args: anytype) !void { |
| 215 | 215 | if (builtin.single_threaded) { |
| 216 | | callFn(func, args); |
| 216 | @call(.auto, func, args); |
| 217 | 217 | return; |
| 218 | 218 | } |
| 219 | 219 | |
| ... | ... | @@ -226,7 +226,7 @@ pub fn spawn(pool: *Pool, comptime func: anytype, args: anytype) !void { |
| 226 | 226 | fn runFn(runnable: *Runnable, _: ?usize) void { |
| 227 | 227 | const run_node: *RunQueue.Node = @fieldParentPtr("data", runnable); |
| 228 | 228 | const closure: *@This() = @alignCast(@fieldParentPtr("run_node", run_node)); |
| 229 | | callFn(func, closure.arguments); |
| 229 | @call(.auto, func, closure.arguments); |
| 230 | 230 | |
| 231 | 231 | // The thread pool's allocator is protected by the mutex. |
| 232 | 232 | const mutex = &closure.pool.mutex; |
| ... | ... | @@ -321,31 +321,3 @@ pub fn waitAndWork(pool: *Pool, wait_group: *WaitGroup) void { |
| 321 | 321 | pub fn getIdCount(pool: *Pool) usize { |
| 322 | 322 | return @intCast(1 + pool.threads.len); |
| 323 | 323 | } |
| 324 | | |
| 325 | | inline fn callFn(comptime f: anytype, args: anytype) void { |
| 326 | | const bad_fn_ret = "expected return type of runFn to be 'void', '!void', noreturn, or !noreturn"; |
| 327 | | |
| 328 | | switch (@typeInfo(@typeInfo(@TypeOf(f)).@"fn".return_type.?)) { |
| 329 | | .void, .noreturn => { |
| 330 | | @call(.auto, f, args); |
| 331 | | }, |
| 332 | | .error_union => |info| { |
| 333 | | switch (info.payload) { |
| 334 | | void, noreturn => { |
| 335 | | @call(.auto, f, args) catch |err| { |
| 336 | | std.debug.print("error: {s}\n", .{@errorName(err)}); |
| 337 | | if (@errorReturnTrace()) |trace| { |
| 338 | | std.debug.dumpStackTrace(trace.*); |
| 339 | | } |
| 340 | | }; |
| 341 | | }, |
| 342 | | else => { |
| 343 | | @compileError(bad_fn_ret); |
| 344 | | }, |
| 345 | | } |
| 346 | | }, |
| 347 | | else => { |
| 348 | | @compileError(bad_fn_ret); |
| 349 | | }, |
| 350 | | } |
| 351 | | } |