work_from_work.c 649 B

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