Skip to content

Commit

Permalink
Make slot available quicker for stopped multishot operations
Browse files Browse the repository at this point in the history
Instead of waiting for all results to be processed wait until not more
events are expected and then make the slot available again.
  • Loading branch information
Thomasdezeeuw committed Jan 14, 2024
1 parent 87539b4 commit 51ad73b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ impl SubmissionQueue {
if let Some(operation) = self.shared.queued_ops.get(op_index.0) {
let mut operation = operation.lock().unwrap();
if let Some(op) = &mut *operation {
if op.is_done() {
if op.no_more_events() {
// Easy path, the operation has already been completed.
*operation = None;
// Unlock defore dropping `resources`, which might take a
Expand Down Expand Up @@ -928,7 +928,7 @@ impl SubmissionQueue {
if let Some(op) = &mut *operation {
log::trace!(op_index = op_index, completion = log::as_debug!(completion); "updating operation");
let is_dropped = op.update(completion);
if is_dropped && op.is_done() {
if is_dropped && op.no_more_events() {
// The Future was previously dropped so no one is waiting on
// the result. We can make the slot avaiable again.
*operation = None;
Expand Down
10 changes: 9 additions & 1 deletion src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,19 @@ impl QueuedOperation {
Poll::Pending
}

/// Returns true if the operation is done.
/// Returns true if the operation is done and processed.
pub(crate) const fn is_done(&self) -> bool {
self.done
}

/// Returns true if no more completion events are expected, but may still
/// contain results.
pub(crate) fn no_more_events(&self) -> bool {
self.done ||
// If a multishot operation returns an error it's stopped.
matches!(&self.kind, QueuedOperationKind::Multishot { results } if results.iter().any(|c|c.result.is_negative()))
}

/// Set the state of the operation as dropped, but still in progress kernel
/// side. This set the waker to `waker` and make `set_result` return `true`.
pub(crate) fn set_dropped(&mut self, waker: Option<task::Waker>) {
Expand Down

0 comments on commit 51ad73b

Please sign in to comment.