Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helpers for getting info about numbers in queques #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/cqe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ impl<'ring> CompletionQueue<'ring> {
Ok(CompletionQueueEvent::new(self.ring, &mut *cqe.assume_init()))
}
}

pub fn num_cqes_ready(&self) -> u32 {
unsafe {
uring_sys::io_uring_cq_ready(self.ring.as_ptr())
}
}

pub fn has_ready_cqes(&self) -> bool {
self.num_cqes_ready() > 0
}
}

unsafe impl<'ring> Send for CompletionQueue<'ring> { }
Expand Down
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ impl IoUring {
self.sq().submit_and_wait_with_timeout(wait_for, duration)
}

pub fn sq_space_left(&self) -> u32 {
SubmissionQueue::new(&self).space_left()
}

pub fn sq_has_space(&self) -> bool {
SubmissionQueue::new(&self).has_space()
}

pub fn peek_for_cqe(&mut self) -> Option<CompletionQueueEvent<'_>> {
unsafe {
let mut cqe = MaybeUninit::uninit();
Expand Down Expand Up @@ -288,6 +296,14 @@ impl IoUring {
pub fn raw_mut(&mut self) -> &mut uring_sys::io_uring {
&mut self.ring
}

pub fn num_cqes_ready(&self) -> u32 {
CompletionQueue::new(&self).num_cqes_ready()
}

pub fn has_ready_cqes(&self) -> bool {
CompletionQueue::new(&self).has_ready_cqes()
}
}

impl Drop for IoUring {
Expand Down
10 changes: 10 additions & 0 deletions src/sqe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ impl<'ring> SubmissionQueue<'ring> {
}
}

pub fn space_left(&self) -> u32 {
unsafe {
uring_sys::io_uring_sq_space_left(self.ring.as_ptr())
}
}

pub fn has_space(&self) -> bool {
self.space_left() > 0
}

/// Submit all events in the queue. Returns the number of submitted events.
///
/// If this function encounters any IO errors an [`io::Error`](std::io::Result) variant is returned.
Expand Down