Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Linux Work Queue

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?

like image 849
max Avatar asked Oct 29 '11 05:10

max


1 Answers

If you want to pass data to your work queue function, just embed the work_struct structure inside your own data structure and use container_of inside 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 at drivers/cpufreq/cpufreq.c (handle_update function) for a simple example. The article below also embeds an example at the end, but it does not use container_of and 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

like image 160
Gnurou Avatar answered Oct 15 '22 15:10

Gnurou