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-07-20 10:38:39-07:00
logb70f12fc40f8f2bf4cce1904cb15a6e365ec95c2
treeda8ca702dca7efac8182c8c69f314ca8a70a1cb1
parent363d7deb8a5dad9f66be84d3bb62a7b129c2bfad

std.Io: delete asyncParallel


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

lib/std/Io.zig+7-61
......@@ -934,8 +934,6 @@ pub const VTable = struct {
934934 context_alignment: std.mem.Alignment,
935935 start: *const fn (context: *const anyopaque, result: *anyopaque) void,
936936 ) ?*AnyFuture,
937 /// Returning `null` indicates resource allocation failed.
938 ///
939937 /// Thread-safe.
940938 asyncConcurrent: *const fn (
941939 /// Corresponds to `Io.userdata`.
......@@ -947,19 +945,6 @@ pub const VTable = struct {
947945 context_alignment: std.mem.Alignment,
948946 start: *const fn (context: *const anyopaque, result: *anyopaque) void,
949947 ) error{OutOfMemory}!*AnyFuture,
950 /// Returning `null` indicates resource allocation failed.
951 ///
952 /// Thread-safe.
953 asyncParallel: *const fn (
954 /// Corresponds to `Io.userdata`.
955 userdata: ?*anyopaque,
956 result_len: usize,
957 result_alignment: std.mem.Alignment,
958 /// Copied and then passed to `start`.
959 context: []const u8,
960 context_alignment: std.mem.Alignment,
961 start: *const fn (context: *const anyopaque, result: *anyopaque) void,
962 ) error{OutOfMemory}!*AnyFuture,
963948 /// Executes `start` asynchronously in a manner such that it cleans itself
964949 /// up. This mode does not support results, await, or cancel.
965950 ///
......@@ -1519,8 +1504,8 @@ pub fn Queue(Elem: type) type {
15191504/// not guaranteed to be available until `await` is called.
15201505///
15211506/// `function` *may* be called immediately, before `async` returns. This has
1522/// weaker guarantees than `asyncConcurrent` and `asyncParallel`, making it the
1523/// most portable and reusable among the async family functions.
1507/// weaker guarantees than `asyncConcurrent`, making more portable and
1508/// reusable.
15241509///
15251510/// See also:
15261511/// * `asyncDetached`
......@@ -1551,13 +1536,12 @@ pub fn async(
15511536}
15521537
15531538/// Calls `function` with `args`, such that the return value of the function is
1554/// not guaranteed to be available until `await` is called, passing control
1555/// flow back to the caller while waiting for any `Io` operations.
1539/// not guaranteed to be available until `await` is called, allowing the caller
1540/// to progress while waiting for any `Io` operations.
15561541///
1557/// This has a weaker guarantee than `asyncParallel`, making it more portable
1558/// and reusable, however it has stronger guarantee than `async`, placing
1559/// restrictions on what kind of `Io` implementations are supported. By calling
1560/// `async` instead, one allows, for example, stackful single-threaded blocking I/O.
1542/// This has stronger guarantee than `async`, placing restrictions on what kind
1543/// of `Io` implementations are supported. By calling `async` instead, one
1544/// allows, for example, stackful single-threaded blocking I/O.
15611545pub fn asyncConcurrent(
15621546 io: Io,
15631547 function: anytype,
......@@ -1584,44 +1568,6 @@ pub fn asyncConcurrent(
15841568 return future;
15851569}
15861570
1587/// Simultaneously calls `function` with `args` while passing control flow back
1588/// to the caller. The return value of the function is not guaranteed to be
1589/// available until `await` is called.
1590///
1591/// This has the strongest guarantees of all async family functions, placing
1592/// the most restrictions on what kind of `Io` implementations are supported.
1593/// By calling `asyncConcurrent` instead, one allows, for example, stackful
1594/// single-threaded non-blocking I/O.
1595///
1596/// See also:
1597/// * `asyncConcurrent`
1598/// * `async`
1599pub fn asyncParallel(
1600 io: Io,
1601 function: anytype,
1602 args: std.meta.ArgsTuple(@TypeOf(function)),
1603) error{OutOfMemory}!Future(@typeInfo(@TypeOf(function)).@"fn".return_type.?) {
1604 const Result = @typeInfo(@TypeOf(function)).@"fn".return_type.?;
1605 const Args = @TypeOf(args);
1606 const TypeErased = struct {
1607 fn start(context: *const anyopaque, result: *anyopaque) void {
1608 const args_casted: *const Args = @alignCast(@ptrCast(context));
1609 const result_casted: *Result = @ptrCast(@alignCast(result));
1610 result_casted.* = @call(.auto, function, args_casted.*);
1611 }
1612 };
1613 var future: Future(Result) = undefined;
1614 future.any_future = try io.vtable.asyncParallel(
1615 io.userdata,
1616 @sizeOf(Result),
1617 .of(Result),
1618 @ptrCast((&args)[0..1]),
1619 .of(Args),
1620 TypeErased.start,
1621 );
1622 return future;
1623}
1624
16251571/// Calls `function` with `args` asynchronously. The resource cleans itself up
16261572/// when the function returns. Does not support await, cancel, or a return value.
16271573///
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,