#include <linux/module.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/init.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/poll.h>
#include <linux/timer.h>
#include <asm/io.h>
#include <asm/system.h>
#include <asm/uaccess.h>
#include <asm/atomic.h>
struct fasync_device {
struct cdev cdev;
struct timer_list timer;
struct fasync_struct *fasync_queue;
};
struct fasync_device fasync_dev;
#define FASYNC_MAJOR 250
static int fasync_major = FASYNC_MAJOR;
static int fasync_open(struct inode *inode, struct file *file)
{
printk(KERN_DEBUG "%s\n", __FUNCTION__);
return 0;
}
static int fasync_fun(int fd, struct file *filp, int on)
{
u32 ret;
ret = fasync_helper(fd, filp, on, &fasync_dev.fasync_queue);
if (ret < 0) {
printk(KERN_ERR "register fasync_helper failed\n");
return ret;
}
printk(KERN_DEBUG "%s\n", __FUNCTION__);
return 0;
}
static int fasync_release(struct inode *inode, struct file *file)
{
printk(KERN_DEBUG "%s\n", __FUNCTION__);
unregister_chrdev_region(MKDEV(fasync_major, 0), 1);
fasync_fun(-1, file, 0);
return 0;
}
static const struct file_operations fasync_ops = {
.owner = THIS_MODULE,
.open = fasync_open,
.release = fasync_release,
.fasync = fasync_fun,
};
static void timer_function(unsigned long para)
{
if (&fasync_dev.fasync_queue) {
kill_fasync(&fasync_dev.fasync_queue, SIGIO, POLL_IN);
printk(KERN_DEBUG "kernel send fasync\n");
}
mod_timer(&fasync_dev.timer, jiffies + 2 * HZ);
}
static int __init fasync_dev_init(void)
{
u32 ret;
dev_t devno = MKDEV(fasync_major, 0);
printk(KERN_DEBUG "%s\n", __FUNCTION__);
ret = register_chrdev_region(devno, 1, "fasync_dev");
if (ret < 0) {
printk(KERN_ERR "register fasync_dev dev resion failed\n");
return ret;
}
cdev_init(&fasync_dev.cdev, &fasync_ops);
fasync_dev.cdev.owner = THIS_MODULE;
fasync_dev.cdev.ops = &fasync_ops;
ret = cdev_add(&fasync_dev.cdev, devno, 1);
if (ret < 0) {
printk(KERN_ERR "add fasync_dev failed\n");
goto err0;
}
printk(KERN_DEBUG "register fasync_dev ok!\n");
init_timer(&fasync_dev.timer);
fasync_dev.timer.expires = jiffies + 2 * HZ;
fasync_dev.timer.function = timer_function;
add_timer(&fasync_dev.timer);
printk(KERN_DEBUG "add timer ok!\n");
return 0;
err0:
unregister_chrdev_region(devno, 1);
return -1;
}
module_init(fasync_dev_init);
static void __exit fasync_dev_exit(void)
{
cdev_del(&fasync_dev.cdev);
unregister_chrdev_region(MKDEV(fasync_major, 0), 1);
del_timer(&fasync_dev.timer);
}
module_exit(fasync_dev_exit);
MODULE_AUTHOR("lei_wang");
MODULE_LICENSE("GPL");
linux内核异步通知用户空间fasync
3星 · 超过75%的资源 需积分: 38 87 浏览量
2015-08-26
16:58:50
上传
评论
收藏 1KB 7Z 举报
luckywang1103
- 粉丝: 569
- 资源: 44
最新资源
- ### 微信小程序概念、使用技巧、优缺点
- 文件I/O基础-I.MX6U嵌入式Linux C应用编程学习笔记基于正点原子阿尔法开发板
- 基于QT的翻金币小游戏
- 餐厅点餐系统(springboot+ssm+html+mysql)含演示视频.zip
- A non-local algorithm for image denoising
- python实现基于VMD-Attention-LSTM的时间序列预测模型项目源码(高分项目).zip
- ### 华为OD(OceanBase Distributed Database)概念、使用技巧、优缺点
- ubuntu的概要介绍与分析
- 基于PHP网络数据包分析工具设计.zip
- 红外图像非均匀性校正算法-红外图像非均匀性校正数据集-基于深度学习的红外图像非均匀性校正-红外图像去噪算法和数据集
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈