Regazi

zad5 lab6

Apr 29th, 2018
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <linux/module.h>
  2.  
  3.  
  4. #define SECONDS_DELAY 2
  5.  
  6.  
  7. static int counter = 1;
  8.  
  9.  
  10. static void delayed_work_handler(struct work_struct *work);
  11.  
  12.  
  13. static struct workqueue_struct *queue;
  14.  
  15.  
  16. static DECLARE_DELAYED_WORK(delayed_work, delayed_work_handler);
  17.  
  18. static void delayed_work_handler(struct work_struct *work)
  19. {
  20. pr_info("Work number: %d\n", counter++);
  21.  
  22.  
  23. if (!queue_delayed_work(queue, &delayed_work, SECONDS_DELAY * HZ))
  24. pr_info("The delayed work was already queued!\n");
  25. }
  26.  
  27.  
  28. static int __init program_init(void)
  29. {
  30.  
  31. queue = create_singlethread_workqueue("work");
  32.  
  33. if (IS_ERR(queue)) {
  34. pr_alert("Error creating a workqueue: %ld\n", PTR_ERR(queue));
  35. return -ENOMEM;
  36. }
  37.  
  38. if (!queue_delayed_work(queue, &delayed_work, SECONDS_DELAY * HZ))
  39. pr_info("The delayed work was already queued!\n");
  40.  
  41. return 0;
  42. }
  43.  
  44.  
  45. static void __exit program_exit(void)
  46. {
  47.  
  48. if (!IS_ERR(queue)) {
  49.  
  50. if (cancel_delayed_work(&delayed_work))
  51. pr_info("Deleting delayed work!\n");
  52.  
  53. destroy_workqueue(queue);
  54. }
  55. }
  56.  
  57. module_init(program_init);
  58. module_exit(program_exit);
  59.  
  60. MODULE_AUTHOR("Mateusz Nachyla Mateusz Orlowski");
  61. MODULE_DESCRIPTION("Zad 5");
  62. MODULE_LICENSE("GPL");
Add Comment
Please, Sign In to add comment