Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <linux/module.h>
- #define SECONDS_DELAY 2
- static int counter = 1;
- static void delayed_work_handler(struct work_struct *work);
- static struct workqueue_struct *queue;
- static DECLARE_DELAYED_WORK(delayed_work, delayed_work_handler);
- static void delayed_work_handler(struct work_struct *work)
- {
- pr_info("Work number: %d\n", counter++);
- if (!queue_delayed_work(queue, &delayed_work, SECONDS_DELAY * HZ))
- pr_info("The delayed work was already queued!\n");
- }
- static int __init program_init(void)
- {
- queue = create_singlethread_workqueue("work");
- if (IS_ERR(queue)) {
- pr_alert("Error creating a workqueue: %ld\n", PTR_ERR(queue));
- return -ENOMEM;
- }
- if (!queue_delayed_work(queue, &delayed_work, SECONDS_DELAY * HZ))
- pr_info("The delayed work was already queued!\n");
- return 0;
- }
- static void __exit program_exit(void)
- {
- if (!IS_ERR(queue)) {
- if (cancel_delayed_work(&delayed_work))
- pr_info("Deleting delayed work!\n");
- destroy_workqueue(queue);
- }
- }
- module_init(program_init);
- module_exit(program_exit);
- MODULE_AUTHOR("Mateusz Nachyla Mateusz Orlowski");
- MODULE_DESCRIPTION("Zad 5");
- MODULE_LICENSE("GPL");
Add Comment
Please, Sign In to add comment