问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/12153797/linux-transfer-parameter-for-function-in-declare-work