当前位置:网站首页>tasklet api使用
tasklet api使用
2022-06-25 16:34:00 【酸菜。】
#include<linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include<linux/fs.h>
#include<linux/slab.h>
#include<linux/timer.h>//timer_list
#include <linux/sched.h>//jiffies
#include <linux/list.h>//container_of
#include <linux/interrupt.h>
MODULE_AUTHOR("Tan xujia");
MODULE_LICENSE("Dual BSD/GPL");
DECLARE_WAIT_QUEUE_HEAD(wq);
struct tasklettest {
struct tasklet_struct tsklt;;
int count;
};
struct tasklettest *ttest;
void
tasklet_fn(unsigned long data)
{
printk("tasklet_fn\n");
struct tasklettest *p =(struct tasklettest*)data;
if (--(p->count)) {
tasklet_hi_schedule(&p->tsklt);
//tasklet_schedule(&p->tsklt);
} else {
//tasklet_kill(&ttest->tsklt);,在这里用这个会有问题
wake_up_interruptible(&wq);//唤醒
printk("wait up\n");
}
}
static
int __init hello_init (void)
{
printk("hello_init\n");
ttest = (struct tasklettest *)kzalloc(sizeof(*ttest), GFP_KERNEL);
ttest->count = 10;
tasklet_init(&ttest->tsklt, tasklet_fn, (unsigned long)ttest);
tasklet_hi_schedule(&ttest->tsklt);
//tasklet_schedule(&ttest->tsklt);
wait_event_interruptible(wq, !ttest->count);//等待条件满足以后,程序继续往下走
printk("wait event\n");
tasklet_kill(&ttest->tsklt);
return 0;
}
static
void __exit hello_exit (void)
{
//tasklet_kill(&ttest->tsklt);
kfree(ttest);
printk("hello_exit\n");
}
module_init(hello_init);
module_exit(hello_exit);
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
obj-m :=tasklet.o
all:
make -C $(KERNELDIR) M=$(PWD) modules
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.* .tmp_versions *.mod *.order *.symvers *.dwo
边栏推荐
猜你喜欢
随机推荐
DDD概念复杂难懂,实际落地如何设计代码实现模型?
Redis系列——概述day1-1
3.条件概率与独立性
根据先序遍历和中序遍历生成后序遍历
JVM內存結構
About: encryption and decryption of rsa+aes data transmission [chapter], project practice (special summary)
Effects and laws
2022-06-17 网工进阶(九)IS-IS-原理、NSAP、NET、区域划分、网络类型、开销值
从TiDB上线阿里云的背后,如何看待云数据库的变革趋势
Paper notes: lbcf: a large scale budget constrained causal forest algorithm
知道这些面试技巧,让你的测试求职少走弯路
Kalman Filter 遇到 Deep Learning : 卡尔曼滤波和深度学习有关的论文
App测试和Web测试的区别
「津津乐道播客」#386 原汤话原食:谁还不是个“白字先生”?
The third day of mysql45
批量--07---断点重提
Collection overview, array encapsulation
Common APIs and exception mechanisms
千万级购物车系统缓存架构方案
Day_ 16 set