内核阻塞式IO
来源:互联网 发布:域名证书有什么用 编辑:程序博客网 时间:2024/05/18 06:49
static ssize_t fifo_read (struct file *f, char __user *p, size_t n, loff_t *off){int size;if(FIFO.cursize == 0)//let this procss go to sleepwait_event_interruptible(FIFO.readqueue, FIFO.cursize != 0);size = n>FIFO.cursize?FIFO.cursize:n;//return 0;int len1, len2;if(FIFO.start <= FIFO.end)// copy once{if(copy_to_user(p, FIFO.qbuf, size)){printk("copy to user fail1\n");return -EINVAL;}}else{len1 = FIFO.maxsize-FIFO.start;if(copy_to_user(p, &FIFO.qbuf[FIFO.start], len1)){printk("copy to user fail2\n");return -EINVAL;}len2 = size-len1;if(copy_to_user(p+len1, FIFO.qbuf, len2)){printk("copy to user fail3\n");return -EINVAL;}}FIFO.start = (FIFO.start+size)%FIFO.maxsize;FIFO.cursize -= size;return size;}static ssize_t fifo_write (struct file *f, const char __user *p, size_t n, loff_t *off){int space = FIFO.maxsize - FIFO.cursize;int size = n>space?space:n;int len1 = (FIFO.maxsize-1 - FIFO.end);int len2;if(!space)return 0;//copy_from_user(&FIFO.qbuf[end+1], p, size);if(len1 >= size)//copy once{if(copy_from_user(&FIFO.qbuf[FIFO.end+1], p, size)){printk("copy from user fail1\n");return -EINVAL;}}else{if(copy_from_user(&FIFO.qbuf[FIFO.end+1], p, len1)){printk("copy from user fail2\n");return -EINVAL;}len2 = size-len1;if(copy_from_user(FIFO.qbuf, p+len1, len2)){printk("copy from user fail3\n");return -EINVAL;}}FIFO.end = (FIFO.end+size)%FIFO.maxsize;FIFO.cursize += size;//woke up processeswake_up_interruptible(&FIFO.readqueue);//wake_up(&FIFO.readqueue);return size;}总结:利用等待队列机制构建内核阻塞IO模型
0 0
- 内核阻塞式IO
- linux内核之阻塞 IO(1)
- linux内核之阻塞 IO(2)
- 内核对轮询IO(阻塞/非阻塞)的实现
- 阻塞式Io
- 非阻塞式IO
- 阻塞式(IO)
- Java IO:阻塞/非阻塞式IO、同步/异步IO
- Java IO:阻塞/非阻塞式IO、同步/异步IO
- 阻塞式io和非阻塞式io(转载…
- socket阻塞式IO和非阻塞式IO
- 阻塞式IO和非阻塞式IO
- JAVA 非阻塞式IO
- 阻塞式IO的困境
- 从操作系统内核看Java非阻塞IO事件检测
- 阻塞IO
- 阻塞、非阻塞IO
- linux下五种IO模型小结(阻塞IO、非阻塞IO、IO复用、信号驱动式IO、异步IO)
- SVM-支持向量机算法概述
- Linux系统调用dup()和dup2()
- AndroidStudio与Java8(二)
- redis 使用
- D. Paths in a Complete Binary Tree CodeForces
- 内核阻塞式IO
- ActionBar为null
- oj2204——使链表中不存在相同元素
- spring实例化类,避免重复加载applicationcontext
- springmvc 定时任务执行2次
- GDB程序调试(四)
- Python threading 多线程
- 基于gsoap的Onvif框架生成
- Android给app签上系统级签名