work_from_work.c 721 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. Declare more work from a workqueue.
  3. */
  4. #include <linux/kernel.h>
  5. #include <linux/module.h>
  6. #include <linux/workqueue.h>
  7. static int i = 0;
  8. static struct workqueue_struct *queue;
  9. static void work_func(struct work_struct *work);
  10. DECLARE_DELAYED_WORK(next_work, work_func);
  11. DECLARE_WORK(work, work_func);
  12. static void work_func(struct work_struct *work)
  13. {
  14. pr_info("%d\n", i);
  15. i++;
  16. queue_delayed_work(queue, &next_work, HZ);
  17. }
  18. static int myinit(void)
  19. {
  20. queue = create_workqueue("myworkqueue");
  21. queue_work(queue, &work);
  22. return 0;
  23. }
  24. static void myexit(void)
  25. {
  26. cancel_delayed_work(&next_work);
  27. flush_workqueue(queue);
  28. destroy_workqueue(queue);
  29. }
  30. module_init(myinit)
  31. module_exit(myexit)
  32. MODULE_LICENSE("GPL");