* [PATCH v2] workqueue: Introduce from_work() helper for cleaner callback declarations
@ 2024-02-27 19:10 Allen Pais
2024-02-27 19:39 ` Tejun Heo
0 siblings, 1 reply; 2+ messages in thread
From: Allen Pais @ 2024-02-27 19:10 UTC (permalink / raw)
To: tj; +Cc: jiangshanlai, linux-kernel
To streamline the transition from tasklets to worqueues, a new helper
function, from_work(), is introduced. This helper, inspired by existing
from_() patterns, utilizes container_of() and eliminates the redundancy
of declaring variable types, leading to more concise and readable code.
The modified code snippet demonstrates the enhanced clarity achieved
with from_wq():
void callback(struct work_struct *w)
{
- struct some_data_structure *local = container_of(w,
struct some_data_structure,
work);
+ struct some_data_structure *local = from_work(local, w, work);
This change aims to facilitate a smoother transition and uphold code
quality standards.
Based on:
git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git disable_work-v3
Signed-off-by: Allen Pais <allen.lkml@gmail.com>
---
include/linux/workqueue.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 7710cd52f7f0..aedfb81f9c49 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -527,6 +527,9 @@ alloc_workqueue(const char *fmt, unsigned int flags, int max_active, ...);
#define create_singlethread_workqueue(name) \
alloc_ordered_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, name)
+#define from_work(var, callback_work, work_fieldname) \
+ container_of(callback_work, typeof(*var), work_fieldname)
+
extern void destroy_workqueue(struct workqueue_struct *wq);
struct workqueue_attrs *alloc_workqueue_attrs(void);
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] workqueue: Introduce from_work() helper for cleaner callback declarations
2024-02-27 19:10 [PATCH v2] workqueue: Introduce from_work() helper for cleaner callback declarations Allen Pais
@ 2024-02-27 19:39 ` Tejun Heo
0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2024-02-27 19:39 UTC (permalink / raw)
To: Allen Pais; +Cc: jiangshanlai, linux-kernel
On Tue, Feb 27, 2024 at 07:10:37PM +0000, Allen Pais wrote:
> To streamline the transition from tasklets to worqueues, a new helper
> function, from_work(), is introduced. This helper, inspired by existing
> from_() patterns, utilizes container_of() and eliminates the redundancy
> of declaring variable types, leading to more concise and readable code.
>
> The modified code snippet demonstrates the enhanced clarity achieved
> with from_wq():
>
> void callback(struct work_struct *w)
> {
> - struct some_data_structure *local = container_of(w,
> struct some_data_structure,
> work);
> + struct some_data_structure *local = from_work(local, w, work);
>
> This change aims to facilitate a smoother transition and uphold code
> quality standards.
>
> Based on:
> git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git disable_work-v3
>
> Signed-off-by: Allen Pais <allen.lkml@gmail.com>
Applied to wq/for-6.9.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-27 19:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-27 19:10 [PATCH v2] workqueue: Introduce from_work() helper for cleaner callback declarations Allen Pais
2024-02-27 19:39 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox