1
0

sched.c 764 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. flush_workqueue(queue);
  27. destroy_workqueue(queue);
  28. }
  29. module_init(sched_init);
  30. module_exit(sched_exit);
  31. MODULE_LICENSE("GPL");
  32. MODULE_DESCRIPTION("Workqueue example");