hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit db8164f92e9de3d54b92e4cc85c80151ac25770f
parent 725c6c8fc05b8883f30da4580f416711498992a3
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue, 19 Oct 2021 15:29:19 +0200

iobus: implement chain and serialize functions

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Miobus/io_uring/handle.ha | 29+++++++++++++++++++++++++++++
1 file changed, 29 insertions(+), 0 deletions(-)

diff --git a/iobus/io_uring/handle.ha b/iobus/io_uring/handle.ha @@ -27,3 +27,32 @@ export fn done(bus: *bus, res: result) void = { free(handle.callbacks); io_uring::cqe_seen(&bus.uring, res); }; + +// Causes a series of I/O handles to be executed serially, waiting for the Nth +// to complete before starting the N+1th. If any of the I/O operations fail, all +// subsequent I/O handles in the chain will be cancelled, returning +// [[errors::cancelled]]. A short read or write (including [[io::EOF]]) is +// considered a failure for this purpose. +// +// All of the I/O handles must be provided as parameters in the order that they +// were created, and must form a continuous sequence of I/O handles as obtained +// from this bus. Discontinuous sequences are not permitted, such that 'h1 = +// read(); h2 = read(); h3 = read(); serial(h1, h3)' is invalid. This function +// must be called prior to any of the handles being submitted to the bus. +export fn chain(items: *handle...) void = { + // TODO: Add assertions to enforce the constraints of this function + for (let i = 0z; i < len(items) - 1; i += 1) { + items[i].sqe.flags |= io_uring::flags::IO_LINK; + }; +}; + +// Serialize behaves similarly to [[chain]], except that an error in I/O +// execution does not cause the remainder of the chain to be cancelled. However, +// a poorly formed I/O submission (such as for an invalid file handle) will +// still cause the chain to be cancelled. +export fn serialize(items: *handle...) void = { + // TODO: Add assertions to enforce the constraints of this function + for (let i = 0z; i < len(items) - 1; i += 1) { + items[i].sqe.flags |= io_uring::flags::IO_HARDLINK; + }; +};