【linux】工作队列简单示例

#include 
#include 
#include 
#include 
struct work_data {
    struct work_struct _work;
    int data;
};
static struct work_data my_work_struct;
static void work_handler(struct work_struct *work) {
    struct work_data *wdata = container_of(work, struct work_data, _work);
    printk(KERN_INFO "Work handler: data = %d\n", wdata->data);
}
//在模块初始化函数中,安排工作队列并提交工作:
static int __init my_module_init(void) {
	INIT_WORK(&my_work_struct._work,work_handler);
    my_work.data = 42;
    schedule_delayed_work(&my_work_struct._work, msecs_to_jiffies(1000));
	//schedule_work(&my_work_struct.work);
    return 0;
}
//在模块退出函数中,取消工作队列
static void __exit my_module_exit(void) {
    cancel_delayed_work_sync(&my_work_struct._work);
    //cancel_work_sync(&my_work_struct.work);
}
module_init(my_module_init);
module_exit(my_module_exit);

https://blog.csdn.net/u012294613/article/details/126666520

你可能感兴趣的:(test,linux,运维,服务器)