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 阅读(2781) 回复(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_...
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); ...
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...
应用程序的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()系统中,指定一个等待时间,在...
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...
本帖最后由 zsmctfy 于 2011-04-11 21:36 编辑 我在看Linux驱动的书(书名:Linux设备驱动详解),书上讲到轮询,还列出了一段代码: static unsigned int XXX_poll(struct file *filp, poll_table *wait) { ...... poll_wait(filp, &dev->r_wait, wait); //加读等待队列头 poll_wait(filp, &dev->w_wait, wait); //加写等待队列头 ...... } 我就是不明白poll_wait这个函数做些什么工作? 还有,X...
想用wait()来获得任一子进程的结束 #include "sys/types.h" #include "sys/wait.h" #include "stdio.h" main() { pid_t pid; if((pid=fork())<0) {printf("fork error."); exit(0); } else if (pid==0) { printf("1 ID:%d\n",getpid()); if ((pid=fork())<0) {printf("fork error."); exit(0); } else if (pid==0) { printf("2 ID:%d\n",getpid()); exit(0); } else sleep(2); } else printf("...