diff --git a/lib/std/Io.zig b/lib/std/Io.zig index 27f51e416f..974d373989 100644 --- a/lib/std/Io.zig +++ b/lib/std/Io.zig @@ -934,8 +934,6 @@ pub const VTable = struct { context_alignment: std.mem.Alignment, start: *const fn (context: *const anyopaque, result: *anyopaque) void, ) ?*AnyFuture, - /// Returning `null` indicates resource allocation failed. - /// /// Thread-safe. asyncConcurrent: *const fn ( /// Corresponds to `Io.userdata`. @@ -947,19 +945,6 @@ pub const VTable = struct { context_alignment: std.mem.Alignment, start: *const fn (context: *const anyopaque, result: *anyopaque) void, ) error{OutOfMemory}!*AnyFuture, - /// Returning `null` indicates resource allocation failed. - /// - /// Thread-safe. - asyncParallel: *const fn ( - /// Corresponds to `Io.userdata`. - userdata: ?*anyopaque, - result_len: usize, - result_alignment: std.mem.Alignment, - /// Copied and then passed to `start`. - context: []const u8, - context_alignment: std.mem.Alignment, - start: *const fn (context: *const anyopaque, result: *anyopaque) void, - ) error{OutOfMemory}!*AnyFuture, /// Executes `start` asynchronously in a manner such that it cleans itself /// up. This mode does not support results, await, or cancel. /// @@ -1519,8 +1504,8 @@ pub fn Queue(Elem: type) type { /// not guaranteed to be available until `await` is called. /// /// `function` *may* be called immediately, before `async` returns. This has -/// weaker guarantees than `asyncConcurrent` and `asyncParallel`, making it the -/// most portable and reusable among the async family functions. +/// weaker guarantees than `asyncConcurrent`, making more portable and +/// reusable. /// /// See also: /// * `asyncDetached` @@ -1551,13 +1536,12 @@ pub fn async( } /// Calls `function` with `args`, such that the return value of the function is -/// not guaranteed to be available until `await` is called, passing control -/// flow back to the caller while waiting for any `Io` operations. +/// not guaranteed to be available until `await` is called, allowing the caller +/// to progress while waiting for any `Io` operations. /// -/// This has a weaker guarantee than `asyncParallel`, making it more portable -/// and reusable, however it has stronger guarantee than `async`, placing -/// restrictions on what kind of `Io` implementations are supported. By calling -/// `async` instead, one allows, for example, stackful single-threaded blocking I/O. +/// This has stronger guarantee than `async`, placing restrictions on what kind +/// of `Io` implementations are supported. By calling `async` instead, one +/// allows, for example, stackful single-threaded blocking I/O. pub fn asyncConcurrent( io: Io, function: anytype, @@ -1584,44 +1568,6 @@ pub fn asyncConcurrent( return future; } -/// Simultaneously calls `function` with `args` while passing control flow back -/// to the caller. The return value of the function is not guaranteed to be -/// available until `await` is called. -/// -/// This has the strongest guarantees of all async family functions, placing -/// the most restrictions on what kind of `Io` implementations are supported. -/// By calling `asyncConcurrent` instead, one allows, for example, stackful -/// single-threaded non-blocking I/O. -/// -/// See also: -/// * `asyncConcurrent` -/// * `async` -pub fn asyncParallel( - io: Io, - function: anytype, - args: std.meta.ArgsTuple(@TypeOf(function)), -) error{OutOfMemory}!Future(@typeInfo(@TypeOf(function)).@"fn".return_type.?) { - const Result = @typeInfo(@TypeOf(function)).@"fn".return_type.?; - const Args = @TypeOf(args); - const TypeErased = struct { - fn start(context: *const anyopaque, result: *anyopaque) void { - const args_casted: *const Args = @alignCast(@ptrCast(context)); - const result_casted: *Result = @ptrCast(@alignCast(result)); - result_casted.* = @call(.auto, function, args_casted.*); - } - }; - var future: Future(Result) = undefined; - future.any_future = try io.vtable.asyncParallel( - io.userdata, - @sizeOf(Result), - .of(Result), - @ptrCast((&args)[0..1]), - .of(Args), - TypeErased.start, - ); - return future; -} - /// Calls `function` with `args` asynchronously. The resource cleans itself up /// when the function returns. Does not support await, cancel, or a return value. /// diff --git a/lib/std/Io/EventLoop.zig b/lib/std/Io/EventLoop.zig index 8b8de73b23..51406e7168 100644 --- a/lib/std/Io/EventLoop.zig +++ b/lib/std/Io/EventLoop.zig @@ -140,7 +140,6 @@ pub fn io(el: *EventLoop) Io { .vtable = &.{ .async = async, .asyncConcurrent = asyncConcurrent, - .asyncParallel = asyncParallel, .await = await, .asyncDetached = asyncDetached, .select = select, @@ -938,23 +937,6 @@ fn asyncConcurrent( return @ptrCast(fiber); } -fn asyncParallel( - userdata: ?*anyopaque, - result_len: usize, - result_alignment: Alignment, - context: []const u8, - context_alignment: Alignment, - start: *const fn (context: *const anyopaque, result: *anyopaque) void, -) error{OutOfMemory}!*std.Io.AnyFuture { - _ = userdata; - _ = result_len; - _ = result_alignment; - _ = context; - _ = context_alignment; - _ = start; - @panic("TODO"); -} - const DetachedClosure = struct { event_loop: *EventLoop, fiber: *Fiber, diff --git a/lib/std/Io/ThreadPool.zig b/lib/std/Io/ThreadPool.zig index 2f10c6a8fa..0006840047 100644 --- a/lib/std/Io/ThreadPool.zig +++ b/lib/std/Io/ThreadPool.zig @@ -86,8 +86,7 @@ pub fn io(pool: *Pool) Io { .userdata = pool, .vtable = &.{ .async = async, - .asyncConcurrent = asyncParallel, - .asyncParallel = asyncParallel, + .asyncConcurrent = asyncConcurrent, .await = await, .asyncDetached = asyncDetached, .cancel = cancel, @@ -220,7 +219,7 @@ fn async( } const pool: *Pool = @alignCast(@ptrCast(userdata)); const cpu_count = pool.cpu_count catch { - return asyncParallel(userdata, result.len, result_alignment, context, context_alignment, start) catch { + return asyncConcurrent(userdata, result.len, result_alignment, context, context_alignment, start) catch { start(context.ptr, result.ptr); return null; }; @@ -284,7 +283,7 @@ fn async( return @ptrCast(closure); } -fn asyncParallel( +fn asyncConcurrent( userdata: ?*anyopaque, result_len: usize, result_alignment: std.mem.Alignment,