Linux work queues are meant to be kernel level threads with process context. I was trying to use it as an alternative to kthread which has no specific process context. But how do I pass data to work queue? work_struct has a data field which is of type atomic_long_t. I could not pass pointer to this field. How do I do it?
Also I could not find a single concrete example of work queue. Can you suggest one?
If you want to pass data to your work queue function, just embed the
work_structstructure inside your own data structure and usecontainer_ofinside your work function to retrieve it.As for a simple example, the kernel is full of it – just
git grep work_struct. You can look atdrivers/cpufreq/cpufreq.c(handle_updatefunction) for a simple example. The article below also embeds an example at the end, but it does not usecontainer_ofand instead relies on the fact that the first member of a structure has the same address as its parent:http://www.ibm.com/developerworks/linux/library/l-tasklets/index.html