mirror of
https://github.com/sysprog21/lkmpg.git
synced 2024-11-24 09:28:09 +08:00
a49c9baffa
schedule_work adds work to global workqueue. In this example, we create a local workqueue. Use the local workqueue by calling queue_work(), instead of putting work on the global workqueue.
34 lines
638 B
C
34 lines
638 B
C
/*
|
|
* sched.c
|
|
*/
|
|
#include <linux/init.h>
|
|
#include <linux/module.h>
|
|
#include <linux/workqueue.h>
|
|
|
|
static struct workqueue_struct *queue = NULL;
|
|
static struct work_struct work;
|
|
|
|
static void work_handler(struct work_struct *data)
|
|
{
|
|
pr_info("work handler function.\n");
|
|
}
|
|
|
|
static int __init sched_init(void)
|
|
{
|
|
queue = alloc_workqueue("HELLOWORLD", WQ_UNBOUND, 1);
|
|
INIT_WORK(&work, work_handler);
|
|
queue_work(queue, &work);
|
|
return 0;
|
|
}
|
|
|
|
static void __exit sched_exit(void)
|
|
{
|
|
destroy_workqueue(queue);
|
|
}
|
|
|
|
module_init(sched_init);
|
|
module_exit(sched_exit);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_DESCRIPTION("Workqueue example");
|