Skip to content

Commit

Permalink
Merge pull request #13 from baruch/add_setup_params_control_alt
Browse files Browse the repository at this point in the history
Add option to set the SetupParameters at setup
  • Loading branch information
tchaloupka committed Apr 14, 2023
2 parents 8f7cf45 + bfc2161 commit 344d5f7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
19 changes: 18 additions & 1 deletion source/during/package.d
Expand Up @@ -36,12 +36,29 @@ nothrow @nogc:
* Returns: On succes it returns 0, `-errno` otherwise.
*/
int setup(ref Uring uring, uint entries = 128, SetupFlags flags = SetupFlags.NONE) @safe
{
SetupParameters params;
params.flags = flags;
return setup(uring, entries, params);
}

/**
* Setup new instance of io_uring into provided `Uring` structure.
*
* Params:
* uring = `Uring` structure to be initialized (must not be already initialized)
* entries = Number of entries to initialize uring with
* params = `SetupParameters` to use to initialize uring.
*
* Returns: On succes it returns 0, `-errno` otherwise.
*/
int setup(ref Uring uring, uint entries, ref SetupParameters params) @safe
{
assert(uring.payload is null, "Uring is already initialized");
uring.payload = () @trusted { return cast(UringDesc*)calloc(1, UringDesc.sizeof); }();
if (uring.payload is null) return -errno;

uring.payload.params.flags = flags;
uring.payload.params = params;
uring.payload.refs = 1;
auto r = io_uring_setup(entries, uring.payload.params);
if (r < 0) return -errno;
Expand Down
26 changes: 26 additions & 0 deletions tests/api.d
Expand Up @@ -195,6 +195,32 @@ unittest
assert(io.map!(c => c.user_data).equal(iota(0, 16)));
}

@("setup parameters")
unittest
{
import during;

Uring io;
SetupParameters params;
params.sq_thread_cpu = 0;
params.flags = SetupFlags.SQPOLL | SetupFlags.SQ_AFF;

auto res = io.setup(16, params);
assert(res >= 0, "Error initializing IO");

res = io.putWith!((ref SubmissionEntry e)
{
e.prepNop();
e.user_data = 43;
})
.submit(1); // submit and wait for 1 completion

assert(res == 1); // One operation submitted
assert(!io.empty); // one operation returned
assert(io.front.user_data == 43);
io.popFront();
}

// @("single mmap")
// unittest
// {
Expand Down

0 comments on commit 344d5f7

Please sign in to comment.