44 lines
938 B
C
44 lines
938 B
C
/*************************************************************************
|
|
> File Name: workqueue.c
|
|
> Author:
|
|
> Mail:
|
|
> Created Time: 2017年04月26日 星期三 08时54分35秒
|
|
************************************************************************/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/workqueue.h>
|
|
|
|
static struct workqueue_struct *queue = NULL;
|
|
static struct work_struct work;
|
|
|
|
static void work_handler(struct work_struct *data)
|
|
{
|
|
printk(KERN_ALERT "work handler function.\n");
|
|
}
|
|
|
|
|
|
static int __init test_init(void)
|
|
{
|
|
queue = create_singlethread_workqueue("helloworld");
|
|
if (!queue)
|
|
goto err;
|
|
|
|
INIT_WORK(&work, work_handler);
|
|
schedule_work(&work);
|
|
|
|
return 0;
|
|
err:
|
|
return -1;
|
|
}
|
|
|
|
|
|
static void __exit test_exit(void)
|
|
{
|
|
destroy_workqueue(queue);
|
|
}
|
|
|
|
MODULE_LICENSE("GPL");
|
|
module_init(test_init);
|
|
module_exit(test_exit);
|