Re: [PATCH 1/3] rust: completion: implement initial abstraction

From: Benno Lossin
Date: Thu Jun 12 2025 - 04:17:12 EST


On Tue Jun 3, 2025 at 10:48 PM CEST, Danilo Krummrich wrote:
> + /// Signal all tasks waiting on this completion.
> + ///
> + /// This method wakes up all tasks waiting on this completion; after this operation the
> + /// completion is permanently done.
> + pub fn complete_all(&self) {
> + // SAFETY: `self.as_raw()` is a pointer to a valid `struct completion`.
> + unsafe { bindings::complete_all(self.as_raw()) };
> + }
> +
> + /// Wait for completion of a task.
> + ///
> + /// This method waits for the completion of a task; it is not interruptible and there is no
> + /// timeout.

Another thing that we should document is weather this function returns
immediately when `complete_all` was already called in the past.

---
Cheers,
Benno

> + pub fn wait_for_completion(&self) {
> + // SAFETY: `self.as_raw()` is a pointer to a valid `struct completion`.
> + unsafe { bindings::wait_for_completion(self.as_raw()) };
> + }
> +}
> +
> +// SAFETY: `Completion` is safe to be send to any task.
> +unsafe impl Send for Completion {}
> +
> +// SAFETY: `Completion` is safe to be accessed concurrently.
> +unsafe impl Sync for Completion {}