1
0

sched.c 736 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * sched.c
  3. */
  4. #include <linux/init.h>
  5. #include <linux/module.h>
  6. #include <linux/workqueue.h>
  7. static struct workqueue_struct *queue = NULL;
  8. static struct work_struct work;
  9. static void work_handler(struct work_struct *data)
  10. {
  11. pr_info("work handler function.\n");
  12. }
  13. static int __init sched_init(void)
  14. {
  15. queue = alloc_workqueue("HELLOWORLD", WQ_UNBOUND, 1);
  16. if (!queue) {
  17. pr_err("Failed to allocate workqueue\n");
  18. return -ENOMEM;
  19. }
  20. INIT_WORK(&work, work_handler);
  21. queue_work(queue, &work);
  22. return 0;
  23. }
  24. static void __exit sched_exit(void)
  25. {
  26. destroy_workqueue(queue);
  27. }
  28. module_init(sched_init);
  29. module_exit(sched_exit);
  30. MODULE_LICENSE("GPL");
  31. MODULE_DESCRIPTION("Workqueue example");