Skip to Content
Linux Device Drivers Development
book

Linux Device Drivers Development

by John Madieu
October 2017
Intermediate to advanced
586 pages
14h 8m
English
Packt Publishing
Content preview from Linux Device Drivers Development

Programming syntax

The following functions are defined in include/linux/workqueue.h:

  • Declare the work and work queue:
struct workqueue_struct *myqueue; 
struct work_struct thework; 
  • Define the worker function (the handler):
void dowork(void *data) {  /* Code goes here */ }; 
  • Initialize our work queue and embed our work into it:
myqueue = create_singlethread_workqueue( "mywork" ); 
INIT_WORK( &thework, dowork, <data-pointer> ); 

We could have also created our work queues through a macro called create_workqueue. The difference between create_workqueue and create_singlethread_workqueue is that the former will create a work queue that in turn will create a separate kernel thread on each and every processor available.

  • Scheduling work:
queue_work(myqueue, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux Device Drivers, Second Edition

Linux Device Drivers, Second Edition

Jonathan Corbet, Alessandro Rubini
Linux Device Drivers, 3rd Edition

Linux Device Drivers, 3rd Edition

Jonathan Corbet, Alessandro Rubini, Greg Kroah-Hartman

Publisher Resources

ISBN: 9781785280009Supplemental Content