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 {...@@ -581,8 +581,6 @@ pub const VTable = struct {
581 context_alignment: std.mem.Alignment,581 context_alignment: std.mem.Alignment,
582 start: *const fn (context: *const anyopaque, result: *anyopaque) void,582 start: *const fn (context: *const anyopaque, result: *anyopaque) void,
583 ) ?*AnyFuture,583 ) ?*AnyFuture,
584 /// Returning `null` indicates resource allocation failed.
585 ///
586 /// Thread-safe.584 /// Thread-safe.
587 asyncConcurrent: *const fn (585 asyncConcurrent: *const fn (
588 /// Corresponds to `Io.userdata`.586 /// Corresponds to `Io.userdata`.
...@@ -594,19 +592,6 @@ pub const VTable = struct {...@@ -594,19 +592,6 @@ pub const VTable = struct {
594 context_alignment: std.mem.Alignment,592 context_alignment: std.mem.Alignment,
595 start: *const fn (context: *const anyopaque, result: *anyopaque) void,593 start: *const fn (context: *const anyopaque, result: *anyopaque) void,
596 ) error{OutOfMemory}!*AnyFuture,594 ) 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,
610 /// Executes `start` asynchronously in a manner such that it cleans itself595 /// Executes `start` asynchronously in a manner such that it cleans itself
611 /// up. This mode does not support results, await, or cancel.596 /// up. This mode does not support results, await, or cancel.
612 ///597 ///
...@@ -1166,8 +1151,8 @@ pub fn Queue(Elem: type) type {...@@ -1166,8 +1151,8 @@ pub fn Queue(Elem: type) type {
1166/// not guaranteed to be available until `await` is called.1151/// not guaranteed to be available until `await` is called.
1167///1152///
1168/// `function` *may* be called immediately, before `async` returns. This has1153/// `function` *may* be called immediately, before `async` returns. This has
1169/// weaker guarantees than `asyncConcurrent` and `asyncParallel`, making it the1154/// weaker guarantees than `asyncConcurrent`, making more portable and
1170/// most portable and reusable among the async family functions.1155/// reusable.
1171///1156///
1172/// See also:1157/// See also:
1173/// * `asyncDetached`1158/// * `asyncDetached`
...@@ -1198,13 +1183,12 @@ pub fn async(...@@ -1198,13 +1183,12 @@ pub fn async(
1198}1183}
11991184
1200/// Calls `function` with `args`, such that the return value of the function is1185/// Calls `function` with `args`, such that the return value of the function is
1201/// not guaranteed to be available until `await` is called, passing control1186/// not guaranteed to be available until `await` is called, allowing the caller
1202/// flow back to the caller while waiting for any `Io` operations.1187/// to progress while waiting for any `Io` operations.
1203///1188///
1204/// This has a weaker guarantee than `asyncParallel`, making it more portable1189/// This has stronger guarantee than `async`, placing restrictions on what kind
1205/// and reusable, however it has stronger guarantee than `async`, placing1190/// of `Io` implementations are supported. By calling `async` instead, one
1206/// restrictions on what kind of `Io` implementations are supported. By calling1191/// allows, for example, stackful single-threaded blocking I/O.
1207/// `async` instead, one allows, for example, stackful single-threaded blocking I/O.
1208pub fn asyncConcurrent(1192pub fn asyncConcurrent(
1209 io: Io,1193 io: Io,
1210 function: anytype,1194 function: anytype,
...@@ -1231,44 +1215,6 @@ pub fn asyncConcurrent(...@@ -1231,44 +1215,6 @@ pub fn asyncConcurrent(
1231 return future;1215 return future;
1232}1216}
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
1272/// Calls `function` with `args` asynchronously. The resource cleans itself up1218/// Calls `function` with `args` asynchronously. The resource cleans itself up
1273/// when the function returns. Does not support await, cancel, or a return value.1219/// when the function returns. Does not support await, cancel, or a return value.
1274///1220///
lib/std/Io/EventLoop.zig-18
...@@ -140,7 +140,6 @@ pub fn io(el: *EventLoop) Io {...@@ -140,7 +140,6 @@ pub fn io(el: *EventLoop) Io {
140 .vtable = &.{140 .vtable = &.{
141 .async = async,141 .async = async,
142 .asyncConcurrent = asyncConcurrent,142 .asyncConcurrent = asyncConcurrent,
143 .asyncParallel = asyncParallel,
144 .await = await,143 .await = await,
145 .asyncDetached = asyncDetached,144 .asyncDetached = asyncDetached,
146 .select = select,145 .select = select,
...@@ -938,23 +937,6 @@ fn asyncConcurrent(...@@ -938,23 +937,6 @@ fn asyncConcurrent(
938 return @ptrCast(fiber);937 return @ptrCast(fiber);
939}938}
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
958const DetachedClosure = struct {940const DetachedClosure = struct {
959 event_loop: *EventLoop,941 event_loop: *EventLoop,
960 fiber: *Fiber,942 fiber: *Fiber,
lib/std/Io/ThreadPool.zig+3-4
...@@ -86,8 +86,7 @@ pub fn io(pool: *Pool) Io {...@@ -86,8 +86,7 @@ pub fn io(pool: *Pool) Io {
86 .userdata = pool,86 .userdata = pool,
87 .vtable = &.{87 .vtable = &.{
88 .async = async,88 .async = async,
89 .asyncConcurrent = asyncParallel,89 .asyncConcurrent = asyncConcurrent,
90 .asyncParallel = asyncParallel,
91 .await = await,90 .await = await,
92 .asyncDetached = asyncDetached,91 .asyncDetached = asyncDetached,
93 .cancel = cancel,92 .cancel = cancel,
...@@ -220,7 +219,7 @@ fn async(...@@ -220,7 +219,7 @@ fn async(
220 }219 }
221 const pool: *Pool = @alignCast(@ptrCast(userdata));220 const pool: *Pool = @alignCast(@ptrCast(userdata));
222 const cpu_count = pool.cpu_count catch {221 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 {
224 start(context.ptr, result.ptr);223 start(context.ptr, result.ptr);
225 return null;224 return null;
226 };225 };
...@@ -284,7 +283,7 @@ fn async(...@@ -284,7 +283,7 @@ fn async(
284 return @ptrCast(closure);283 return @ptrCast(closure);
285}284}
286285
287fn asyncParallel(286fn asyncConcurrent(
288 userdata: ?*anyopaque,287 userdata: ?*anyopaque,
289 result_len: usize,288 result_len: usize,
290 result_alignment: std.mem.Alignment,289 result_alignment: std.mem.Alignment,