poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p) 研究poll_wait,参数里面的等待队列wait_address,为什么都用add_wait_queue,加入队列中,然后调用while去等,要么就是用wait_event去等待唤醒? 最好说说这个队列应该怎么搞?
by superzx727 - 内核源码 - 2007-12-24 11:03:35 阅读(2780) 回复(0)
linux设备驱动程序第三版有如下代码: static unsigned int scull_p_poll(struct file *filp, poll_table *wait) { struct scull_pipe *dev = filp->private_data; unsigned int mask = 0; /* * The buffer is circular; it is considered full * if "wp" is right behind "rp" and empty if the * two are equal. */ down(&dev->sem); poll_...
ldd 第165页的 poll 函数,代码如下[code]unsigned int scullp_poll(struct file *filp,poll_table *wait) { unsigned int mask = 0; down(&scullp->sem); poll_wait(filp,&scullp->inq,wait); poll_wait(filp,&scullp->outq,wait); if(scullp->rp != scullp->wp) mask |= pollIN | pollRDNORM; if(spacefree()) mask |= pollOUT | pollWRNORM; up(&scullp->sem); return mask; }[/code]把这个p...
本帖最后由 lanlovehua 于 2010-09-27 15:59 编辑 [code]typedef void (*poll_queue_proc)(struct file *, wait_queue_head_t *, struct poll_table_struct *); typedef struct poll_table_struct { poll_queue_proc qproc; } poll_table; static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p) { if (p && wait_address) p->qproc(filp, wait_ad...
linux设备驱动程序第三版有如下代码: static unsigned int scull_p_poll(struct file *filp, poll_table *wait) { struct scull_pipe *dev = filp->private_data; unsigned int mask = 0; /* * The buffer is circular; it is considered full * if "wp" is right behind "rp" and empty if the * two are equal. */ down(&dev->sem); ...
本帖最后由 langwan1314 于 2010-07-06 22:13 编辑 poll()函数:这个函数是某些Unix系统提供的用于执行与select()函数同等功能的函数,下面是这个函数的声明: #include <poll.h> int poll(struct pollfd fds[], nfds_t nfds, int timeout); 参数说明: fds:是一个struct pollfd结构类型的数组,用于存放需要检测其状态的Socket描述符;每当调用这个函数之后,系统不会清空这个数组,操作起来比较方便;特别是对于socket连...
应用程序的select()系统调用,调用驱动中的poll()方法。 不理解的是在下面的poll()方法实现中,首先调用poll_wait将等待队列添加到wait结构中,接下来是个判断语句 if (dev->rp != dev->wp) mask |= pollIN | pollRDNORM; /* readable */ 只考虑可读情况。如果这个if语句的条件不满足,那么就不会返回可读,也就是返回0。那么在这里怎么实现阻塞的呢?也就是说如果在应用的select()系统中,指定一个等待时间,在...
应用程序的select()系统调用,调用驱动中的poll()方法。 不理解的是在下面的poll()方法实现中,首先调用poll_wait将等待队列添加到wait结构中,接下来是个判断语句 if (dev->rp != dev->wp) mask |= pollIN | pollRDNORM; /* readable */ 只考虑可读情况。如果这个if语句的条件不满足,那么就不会返回可读,也就是返回0。那么在这里怎么实现阻塞的呢?也就是说如果在应用的select()系统中,指定一个等待时间,在...
五个I/O模型 1.阻塞I/O 2.非阻塞I/O 3.I/O复用(select和poll) 4.信号驱动I/O(SIGIO) 5.异步I/O 阻塞 I/O模型 进程调用recvfrom,此系统调用直到数据报到达且拷贝到应用缓冲区或是出错才返回。最常见的错误是系统调用被信号中断,进程阻塞的整段时间是指从调用recvfrom开始到它返回的这段时间,当进程返回成功指示时,应用进程开始处理数据报。 非阻塞方式 当请求的I/O操作不能完成时,不让进程睡眠,而应返回一个错误。 前三次调...
tatic unsigned int scull_p_poll(struct file *filp, poll_table *wait) { struct scull_pipe *dev = filp->private_data; unsigned int mask = 0; /* * The buffer is circular; it is considered full * if "wp" is right behind "rp" and empty if the * two are equal. */ down(&dev->sem); poll_wait(filp, &dev->inq, wait); // poll_wa...