workqueue: Introduce from_wq() helper for cleaner callback declarations
PATCH 1/1 workqueue: Introduce from_wq() helper for cleaner callback declarations
To streamline the transition from tasklets to worqueues, a new helper function, from_wq(), 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_wq(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
--- include/linux/workqueue.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/workqueue.h +3 -0
@@ -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_wq (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 );
Signature · 1 line
2.17.1
Tejun Heo
maintainerQuoted 8 lines · Allen Pais
To streamline the transition from tasklets to worqueues, a new helper function,
from_wq(), is introduced. This helper, inspired by existingfrom_()patterns, utilizescontainer_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():
Quoted 6 lines
void
callback(struct work_struct *w)
{
- structsome_data_structure*local = container_of(w,
structsome_data_structure, work);
+ structsome_data_structure*local =from_wq(local, w, work);
I'm not necessarily against it but it's a bit meh in terms of how much it saves. Also, can you please name it from_work()?
Thanks.
Signature · 1 line
tejun
Quoted 18 lines · Allen Pais
Quoted 8 lines
To streamline the transition from tasklets to worqueues, a new helper function,
from_wq(), is introduced. This helper, inspired by existingfrom_()patterns, utilizescontainer_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():Quoted 6 lines
void
callback(struct work_struct *w)
{
- structsome_data_structure*local = container_of(w,
structsome_data_structure, work);
+ structsome_data_structure*local =from_wq(local, w, work);
Quoted 2 lines
I'm not necessarily against it but it's a bit meh in terms of how much it saves. Also, can you please name it
from_work()?
I agree :). It does help a little in conversion. Sure, will send out a v2 right away.
Thanks.
Quoted 5 lines
Thanks.
Signature · 1 line
tejun