mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
std.Io: delete asyncParallel
This commit is contained in:
parent
363d7deb8a
commit
b70f12fc40
@ -934,8 +934,6 @@ pub const VTable = struct {
|
|||||||
context_alignment: std.mem.Alignment,
|
context_alignment: std.mem.Alignment,
|
||||||
start: *const fn (context: *const anyopaque, result: *anyopaque) void,
|
start: *const fn (context: *const anyopaque, result: *anyopaque) void,
|
||||||
) ?*AnyFuture,
|
) ?*AnyFuture,
|
||||||
/// Returning `null` indicates resource allocation failed.
|
|
||||||
///
|
|
||||||
/// Thread-safe.
|
/// Thread-safe.
|
||||||
asyncConcurrent: *const fn (
|
asyncConcurrent: *const fn (
|
||||||
/// Corresponds to `Io.userdata`.
|
/// Corresponds to `Io.userdata`.
|
||||||
@ -947,19 +945,6 @@ pub const VTable = struct {
|
|||||||
context_alignment: std.mem.Alignment,
|
context_alignment: std.mem.Alignment,
|
||||||
start: *const fn (context: *const anyopaque, result: *anyopaque) void,
|
start: *const fn (context: *const anyopaque, result: *anyopaque) void,
|
||||||
) error{OutOfMemory}!*AnyFuture,
|
) 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
|
/// Executes `start` asynchronously in a manner such that it cleans itself
|
||||||
/// up. This mode does not support results, await, or cancel.
|
/// 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.
|
/// not guaranteed to be available until `await` is called.
|
||||||
///
|
///
|
||||||
/// `function` *may* be called immediately, before `async` returns. This has
|
/// `function` *may* be called immediately, before `async` returns. This has
|
||||||
/// weaker guarantees than `asyncConcurrent` and `asyncParallel`, making it the
|
/// weaker guarantees than `asyncConcurrent`, making more portable and
|
||||||
/// most portable and reusable among the async family functions.
|
/// reusable.
|
||||||
///
|
///
|
||||||
/// See also:
|
/// See also:
|
||||||
/// * `asyncDetached`
|
/// * `asyncDetached`
|
||||||
@ -1551,13 +1536,12 @@ pub fn async(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Calls `function` with `args`, such that the return value of the function is
|
/// Calls `function` with `args`, such that the return value of the function is
|
||||||
/// not guaranteed to be available until `await` is called, passing control
|
/// not guaranteed to be available until `await` is called, allowing the caller
|
||||||
/// flow back to the caller while waiting for any `Io` operations.
|
/// to progress while waiting for any `Io` operations.
|
||||||
///
|
///
|
||||||
/// This has a weaker guarantee than `asyncParallel`, making it more portable
|
/// This has stronger guarantee than `async`, placing restrictions on what kind
|
||||||
/// and reusable, however it has stronger guarantee than `async`, placing
|
/// of `Io` implementations are supported. By calling `async` instead, one
|
||||||
/// restrictions on what kind of `Io` implementations are supported. By calling
|
/// allows, for example, stackful single-threaded blocking I/O.
|
||||||
/// `async` instead, one allows, for example, stackful single-threaded blocking I/O.
|
|
||||||
pub fn asyncConcurrent(
|
pub fn asyncConcurrent(
|
||||||
io: Io,
|
io: Io,
|
||||||
function: anytype,
|
function: anytype,
|
||||||
@ -1584,44 +1568,6 @@ pub fn asyncConcurrent(
|
|||||||
return future;
|
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
|
/// Calls `function` with `args` asynchronously. The resource cleans itself up
|
||||||
/// when the function returns. Does not support await, cancel, or a return value.
|
/// when the function returns. Does not support await, cancel, or a return value.
|
||||||
///
|
///
|
||||||
|
|||||||
@ -140,7 +140,6 @@ pub fn io(el: *EventLoop) Io {
|
|||||||
.vtable = &.{
|
.vtable = &.{
|
||||||
.async = async,
|
.async = async,
|
||||||
.asyncConcurrent = asyncConcurrent,
|
.asyncConcurrent = asyncConcurrent,
|
||||||
.asyncParallel = asyncParallel,
|
|
||||||
.await = await,
|
.await = await,
|
||||||
.asyncDetached = asyncDetached,
|
.asyncDetached = asyncDetached,
|
||||||
.select = select,
|
.select = select,
|
||||||
@ -938,23 +937,6 @@ fn asyncConcurrent(
|
|||||||
return @ptrCast(fiber);
|
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 {
|
const DetachedClosure = struct {
|
||||||
event_loop: *EventLoop,
|
event_loop: *EventLoop,
|
||||||
fiber: *Fiber,
|
fiber: *Fiber,
|
||||||
|
|||||||
@ -86,8 +86,7 @@ pub fn io(pool: *Pool) Io {
|
|||||||
.userdata = pool,
|
.userdata = pool,
|
||||||
.vtable = &.{
|
.vtable = &.{
|
||||||
.async = async,
|
.async = async,
|
||||||
.asyncConcurrent = asyncParallel,
|
.asyncConcurrent = asyncConcurrent,
|
||||||
.asyncParallel = asyncParallel,
|
|
||||||
.await = await,
|
.await = await,
|
||||||
.asyncDetached = asyncDetached,
|
.asyncDetached = asyncDetached,
|
||||||
.cancel = cancel,
|
.cancel = cancel,
|
||||||
@ -220,7 +219,7 @@ fn async(
|
|||||||
}
|
}
|
||||||
const pool: *Pool = @alignCast(@ptrCast(userdata));
|
const pool: *Pool = @alignCast(@ptrCast(userdata));
|
||||||
const cpu_count = pool.cpu_count catch {
|
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);
|
start(context.ptr, result.ptr);
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
@ -284,7 +283,7 @@ fn async(
|
|||||||
return @ptrCast(closure);
|
return @ptrCast(closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn asyncParallel(
|
fn asyncConcurrent(
|
||||||
userdata: ?*anyopaque,
|
userdata: ?*anyopaque,
|
||||||
result_len: usize,
|
result_len: usize,
|
||||||
result_alignment: std.mem.Alignment,
|
result_alignment: std.mem.Alignment,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user