Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux transfer parameter for function in DECLARE_WORK

I try to programm a Event-Workqueue, but I meet some problems.

I use a Linux 2.6.36 Kernel. And the DECLARE_WORK function changed from 3 parameters to 2.

The question is, the old declaration was

 DECLARE_WORK  (struct work_struct name,  void (*func)(void *),  void *data); 

And the new one is

 DECLARE_WORK  (struct work_struct name,  void (*func)(void *)); 

I think the void *data pointer was to give the func parameters. Is that right? And how can I do that with the new version of DECLARE_WORK?

Thanks for the help

Peter

like image 944
Peter Avatar asked Mar 10 '26 02:03

Peter


1 Answers

DECLARE_WORK is primarily for static work items, where no instance data is needed. You want INIT_WORK. Use this to initialize a work_struct that is a member of another structure (of your choosing), then use container_of in the callback to get the pointer to the containing structure. This container_of pattern is extremely common in the Linux kernel, so it's a good idea to get familiar with it!

You can see an example of this with wl1271_netstack_work - take a look at the initialization point and the callback.

like image 95
bdonlan Avatar answered Mar 11 '26 23:03

bdonlan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!