From: "Gary Guo" <gary@garyguo.net>
To: "Danilo Krummrich" <dakr@kernel.org>, <tj@kernel.org>,
<jiangshanlai@gmail.com>, <aliceryhl@google.com>,
<ojeda@kernel.org>, <boqun@kernel.org>, <gary@garyguo.net>,
<bjorn3_gh@protonmail.com>, <lossin@kernel.org>,
<a.hindborg@kernel.org>, <tmgross@umich.edu>,
<daniel.almeida@collabora.com>, <tamird@kernel.org>,
<acourbot@nvidia.com>, <work@onurozkan.dev>,
<jhubbard@nvidia.com>
Cc: <rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<driver-core@lists.linux.dev>
Subject: Re: [PATCH v2 6/6] rust: workqueue: add ScopedWork for non-'static work items
Date: Wed, 02 Sep 2026 15:52:15 +0100 [thread overview]
Message-ID: <DL4WZ011ISU6.30MN524IETGKI@garyguo.net> (raw)
In-Reply-To: <20260807165252.3849875-7-dakr@kernel.org>
On Fri Aug 7, 2026 at 5:52 PM BST, Danilo Krummrich wrote:
> Add ScopedWork<T>, a work item wrapper whose destructor calls
> cancel_work_sync(), allowing T to carry non-'static lifetimes. Ownership
> of the data is not transferred to the workqueue; instead, the
> synchronous cancellation on drop guarantees the work function is not
> running when the data is freed.
>
> ScopedWork uses the existing Work/HasWork/WorkItem infrastructure with
> NonNull<ScopedWorkRef<T>> as WorkItem::Pointer for the callback path,
> and implements RawWorkItem for &ScopedWork<T> and &ScopedWorkRef<T> for
> the enqueue path (requiring T: Sync for cross-thread shared access
> safety).
>
> Two enqueue paths are provided:
> - Queue::enqueue_scoped() (unsafe): the caller must ensure the work
> item is not forgotten.
> - ScopedQueue::enqueue() (safe): when the work item's lifetime
> satisfies the queue's 'scope bound.
>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> ---
> rust/kernel/workqueue/mod.rs | 46 +++-
> rust/kernel/workqueue/scoped.rs | 442 +++++++++++++++++++++++++++++---
> 2 files changed, 444 insertions(+), 44 deletions(-)
>
> [snip]
>
> +impl<T: ScopedWorkItem> ScopedWork<T> {
> + /// Creates a pin-initializer for a new scoped work item.
> + ///
> + /// Use [`new_scoped_work!`] to automatically provide the lock class key.
> + #[inline]
> + pub fn new<E>(
> + name: &'static CStr,
> + key: Pin<&'static LockClassKey>,
> + init: impl PinInit<T, E>,
> + ) -> impl PinInit<Self, Error>
This should just propagate error and return `E` (you might need the `? E`
annotation for it).
> + where
> + Error: From<E>,
> + {
> + try_pin_init!(Self {
> + inner <- Opaque::pin_init(try_pin_init!(ScopedWorkRef::<T> {
> + work <- Work::new(name, key),
> + data <- init,
> + })),
> + })
> + }
> +}
Best,
Gary
prev parent reply other threads:[~2026-09-02 14:52 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 16:52 [PATCH v2 0/6] workqueue: OwnedQueue, ScopedQueue and ScopedWork Danilo Krummrich
2026-08-07 16:52 ` [PATCH v2 1/6] rust: workqueue: replace deprecated system_wq with system_{percpu,dfl}_wq Danilo Krummrich
2026-08-27 17:12 ` Daniel Almeida
2026-08-07 16:52 ` [PATCH v2 2/6] rust: workqueue: restrict delayed work to global wqs Danilo Krummrich
2026-08-27 17:13 ` Daniel Almeida
2026-08-07 16:52 ` [PATCH v2 3/6] rust: workqueue: create workqueue subdirectory Danilo Krummrich
2026-08-27 17:16 ` Daniel Almeida
2026-08-07 16:52 ` [PATCH v2 4/6] rust: workqueue: add creation of workqueues Danilo Krummrich
2026-08-07 22:39 ` Danilo Krummrich
2026-08-27 19:25 ` Daniel Almeida
2026-08-27 19:25 ` Daniel Almeida
2026-08-07 16:52 ` [PATCH v2 5/6] rust: workqueue: add ScopedQueue for lifetime bound items Danilo Krummrich
2026-08-27 21:39 ` Daniel Almeida
2026-09-02 14:40 ` Alice Ryhl
2026-08-07 16:52 ` [PATCH v2 6/6] rust: workqueue: add ScopedWork for non-'static work items Danilo Krummrich
2026-08-07 18:35 ` Danilo Krummrich
2026-08-27 23:07 ` Daniel Almeida
2026-09-02 14:49 ` Alice Ryhl
2026-09-02 14:52 ` Gary Guo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DL4WZ011ISU6.30MN524IETGKI@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=driver-core@lists.linux.dev \
--cc=jhubbard@nvidia.com \
--cc=jiangshanlai@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tj@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox