Linux transfer parameter for function in DECLARE_WORK

房东的猫 提交于 2019-12-04 14:05:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!