io_uring: add msg_ring functionality #157
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
io_uring has a function called msg_ring which adds a CQE to a target
ring, which may be operating in a different thread. This can be very
valuable to wakeup a sleeping thread while also giving it data to
operate with.
Zig std doesn't have the prep function from liburing yet, so we emulate
how that function works. Specifically, we are emulating
io_uring_prep_msg_ring_cqe_flags. We are using the *cqe_flags variant so
that we can set a flag on the receiver's CQE. Because of how completion
callbacks work, the same callback will be called twice: once with the
sender's loop and once with the receiver's loop. By setting a flag, we
can distinguish between these. The method allows passing a u32 value
through as extra data, in addition to the pointer. We also pass this
through, but when we detect we are the sender of the message we return a
null. Only the receiver of the message will get the value contained
here.