diff options
Diffstat (limited to 'src/thread_pool.zig')
-rw-r--r-- | src/thread_pool.zig | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/thread_pool.zig b/src/thread_pool.zig index c983072c1..807bebc6c 100644 --- a/src/thread_pool.zig +++ b/src/thread_pool.zig @@ -247,7 +247,18 @@ pub fn do( comptime Run: anytype, values: anytype, ) !void { - return try Do(this, allocator, wg, @TypeOf(ctx), ctx, Run, @TypeOf(values), values); + return try Do(this, allocator, wg, @TypeOf(ctx), ctx, Run, @TypeOf(values), values, false); +} + +pub fn doPtr( + this: *ThreadPool, + allocator: std.mem.Allocator, + wg: ?*WaitGroup, + ctx: anytype, + comptime Run: anytype, + values: anytype, +) !void { + return try Do(this, allocator, wg, @TypeOf(ctx), ctx, Run, @TypeOf(values), values, true); } pub fn Do( @@ -259,6 +270,7 @@ pub fn Do( comptime Function: anytype, comptime ValuesType: type, values: ValuesType, + comptime as_ptr: bool, ) !void { if (values.len == 0) return; @@ -282,9 +294,16 @@ pub fn Do( const Runner = struct { pub fn call(ctx_: WaitContext, values_: ValuesType, i: usize) void { - for (values_) |v, j| { - Function(ctx_.ctx, v, i + j); + if (comptime as_ptr) { + for (values_) |*v, j| { + Function(ctx_.ctx, v, i + j); + } + } else { + for (values_) |v, j| { + Function(ctx_.ctx, v, i + j); + } } + ctx_.wait_group.finish(); } }; |