authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-18 09:41:48-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-02 16:30:59-07:00
log2746239fd3f9ead09569a1a073d7a3c8819d5e11
tree946692082db9dcf001000380bcb98e22a1dacbb2
parent25b2954c0c86145948834b31b8edb88aeb4d40a0

std.Io: delete asyncParallel


3 files changed, 10 insertions(+), 83 deletions(-)

lib/std/Io.zig+7-61
......@@ -581,8 +581,6 @@ pub const VTable = struct {
581581 context_alignment: std.mem.Alignment,
582582 start: *const fn (context: *const anyopaque, result: *anyopaque) void,
583583 ) ?*AnyFuture,
584 /// Returning `null` indicates resource allocation failed.
585 ///
586584 /// Thread-safe.
587585 asyncConcurrent: *const fn (
588586 /// Corresponds to `Io.userdata`.
......@@ -594,19 +592,6 @@ pub const VTable = struct {
594592 context_alignment: std.mem.Alignment,
595593 start: *const fn (context: *const anyopaque, result: *anyopaque) void,
596594 ) error{OutOfMemory}!*AnyFuture,
597 /// Returning `null` indicates resource allocation failed.
598 ///
599 /// Thread-safe.
600 asyncParallel: *const fn (
601 /// Corresponds to `Io.userdata`.
602 userdata: ?*anyopaque,
603 result_len: usize,
604 result_alignment: std.mem.Alignment,
605 /// Copied and then passed to `start`.
606 context: []const u8,
607 context_alignment: std.mem.Alignment,
608 start: *const fn (context: *const anyopaque, result: *anyopaque) void,
609 ) error{OutOfMemory}!*AnyFuture,
610595 /// Executes `start` asynchronously in a manner such that it cleans itself
611596 /// up. This mode does not support results, await, or cancel.
612597 ///
......@@ -1166,8 +1151,8 @@ pub fn Queue(Elem: type) type {
11661151/// not guaranteed to be available until `await` is called.
11671152///
11681153/// `function` *may* be called immediately, before `async` returns. This has
1169/// weaker guarantees than `asyncConcurrent` and `asyncParallel`, making it the
1170/// most portable and reusable among the async family functions.
1154/// weaker guarantees than `asyncConcurrent`, making more portable and
1155/// reusable.
11711156///
11721157/// See also:
11731158/// * `asyncDetached`
......@@ -1198,13 +1183,12 @@ pub fn async(
11981183}
11991184
12001185/// Calls `function` with `args`, such that the return value of the function is
1201/// not guaranteed to be available until `await` is called, passing control
1202/// flow back to the caller while waiting for any `Io` operations.
1186/// not guaranteed to be available until `await` is called, allowing the caller
1187/// to progress while waiting for any `Io` operations.
12031188///
1204/// This has a weaker guarantee than `asyncParallel`, making it more portable
1205/// and reusable, however it has stronger guarantee than `async`, placing
1206/// restrictions on what kind of `Io` implementations are supported. By calling
1207/// `async` instead, one allows, for example, stackful single-threaded blocking I/O.
1189/// This has stronger guarantee than `async`, placing restrictions on what kind
1190/// of `Io` implementations are supported. By calling `async` instead, one
1191/// allows, for example, stackful single-threaded blocking I/O.
12081192pub fn asyncConcurrent(
12091193 io: Io,
12101194 function: anytype,
......@@ -1231,44 +1215,6 @@ pub fn asyncConcurrent(
12311215 return future;
12321216}
12331217
1234/// Simultaneously calls `function` with `args` while passing control flow back
1235/// to the caller. The return value of the function is not guaranteed to be
1236/// available until `await` is called.
1237///
1238/// This has the strongest guarantees of all async family functions, placing
1239/// the most restrictions on what kind of `Io` implementations are supported.
1240/// By calling `asyncConcurrent` instead, one allows, for example, stackful
1241/// single-threaded non-blocking I/O.
1242///
1243/// See also:
1244/// * `asyncConcurrent`
1245/// * `async`
1246pub fn asyncParallel(
1247 io: Io,
1248 function: anytype,
1249 args: std.meta.ArgsTuple(@TypeOf(function)),
1250) error{OutOfMemory}!Future(@typeInfo(@TypeOf(function)).@"fn".return_type.?) {
1251 const Result = @typeInfo(@TypeOf(function)).@"fn".return_type.?;
1252 const Args = @TypeOf(args);
1253 const TypeErased = struct {
1254 fn start(context: *const anyopaque, result: *anyopaque) void {
1255 const args_casted: *const Args = @alignCast(@ptrCast(context));
1256 const result_casted: *Result = @ptrCast(@alignCast(result));
1257 result_casted.* = @call(.auto, function, args_casted.*);
1258 }
1259 };
1260 var future: Future(Result) = undefined;
1261 future.any_future = try io.vtable.asyncParallel(
1262 io.userdata,
1263 @sizeOf(Result),
1264 .of(Result),
1265 @ptrCast((&args)[0..1]),
1266 .of(Args),
1267 TypeErased.start,
1268 );
1269 return future;
1270}
1271
12721218/// Calls `function` with `args` asynchronously. The resource cleans itself up
12731219/// when the function returns. Does not support await, cancel, or a return value.
12741220///
lib/std/Io/EventLoop.zig-18
......@@ -140,7 +140,6 @@ pub fn io(el: *EventLoop) Io {
140140 .vtable = &.{
141141 .async = async,
142142 .asyncConcurrent = asyncConcurrent,
143 .asyncParallel = asyncParallel,
144143 .await = await,
145144 .asyncDetached = asyncDetached,
146145 .select = select,
......@@ -938,23 +937,6 @@ fn asyncConcurrent(
938937 return @ptrCast(fiber);
939938}
940939
941fn asyncParallel(
942 userdata: ?*anyopaque,
943 result_len: usize,
944 result_alignment: Alignment,
945 context: []const u8,
946 context_alignment: Alignment,
947 start: *const fn (context: *const anyopaque, result: *anyopaque) void,
948) error{OutOfMemory}!*std.Io.AnyFuture {
949 _ = userdata;
950 _ = result_len;
951 _ = result_alignment;
952 _ = context;
953 _ = context_alignment;
954 _ = start;
955 @panic("TODO");
956}
957
958940const DetachedClosure = struct {
959941 event_loop: *EventLoop,
960942 fiber: *Fiber,
lib/std/Io/ThreadPool.zig+3-4
......@@ -86,8 +86,7 @@ pub fn io(pool: *Pool) Io {
8686 .userdata = pool,
8787 .vtable = &.{
8888 .async = async,
89 .asyncConcurrent = asyncParallel,
90 .asyncParallel = asyncParallel,
89 .asyncConcurrent = asyncConcurrent,
9190 .await = await,
9291 .asyncDetached = asyncDetached,
9392 .cancel = cancel,
......@@ -220,7 +219,7 @@ fn async(
220219 }
221220 const pool: *Pool = @alignCast(@ptrCast(userdata));
222221 const cpu_count = pool.cpu_count catch {
223 return asyncParallel(userdata, result.len, result_alignment, context, context_alignment, start) catch {
222 return asyncConcurrent(userdata, result.len, result_alignment, context, context_alignment, start) catch {
224223 start(context.ptr, result.ptr);
225224 return null;
226225 };
......@@ -284,7 +283,7 @@ fn async(
284283 return @ptrCast(closure);
285284}
286285
287fn asyncParallel(
286fn asyncConcurrent(
288287 userdata: ?*anyopaque,
289288 result_len: usize,
290289 result_alignment: std.mem.Alignment,