epoll()无论涉及wait队列分析
2015-07-27 20:20
489 查看
事件1. epfd-file->eventpoll->wq:
struct eventpoll {...
wait_queue_head_t wq; //用于epoll_pwait()事件的等待队列 情况1分析
struct list_head rdllist; //就绪的fd队列 ready list
struct rb_root rbr; //红黑树根,epitem->rbn为红黑树结构的节点
struct file *file; //epoll文件系统中构建的虚拟文件
...
};
主要用于epoll_pwait()时候,判定epfd-file->eventpoll->rdlist(就绪fd)是否为空。假设为空而且epoll_pwait()为堵塞调用。那么将当前进程将被挂到epfd-file->eventpoll->wq中,而且当前进程进入堵塞等待,直到rdlist非空的时候唤起epfd-file->eventpoll->poll_wait链表中的进程(相互排斥唤起和非相互排斥唤起?)唤起的回调函数默觉得wake_up_interruptible或者wake_up
情况2.被监听的fd->poll_wait
将被监听套接字fd在epoll期间构建的epitem和eppoll_entryepitem{
struct rb_node rbn; //epitem挂在rbtree上的节点信息
struct list_head rdllink; //假设fd就绪,将挂入ready list
struct eventpoll *ep; //所属主eventpoll(维护rbtree rdllist poll_wait队列...)
struct epoll_event event; //fd上监听的事件
}
struct eppoll_entry {
struct list_head llink;
struct epitem *base; //所属epitem
wait_queue_t wait; //作为一元素挂入被监听fd的wait队列中
wait_queue_head_t *whead; //被监听fd的等待队列。假设fd为socket。那么whead为sock->sk_sleep
};
eppoll_entry主要完毕epitem和epitem事件发生时的callback函数之间的关联。
首先将eppoll_entry的whead指向fd的设备等待队列(同select中的wait_address)。
然后初始化eppoll_entry的base变量指向epitem。
最后通过add_wait_queue将epoll_entry挂载到fd的设备等待队列上。
当在设备硬件数据到来时,硬件中断处理函数中会唤醒该等待队列上等待的进程时,会调用唤醒函数ep_poll_callback(ep_poll_callback: 当fd上出发事件后。将epitem中的rdllink节点增加到readlist中(epfd-file->eventpoll->rdlist))
对照:
1和2对照,主要是等待队列的回调函数用处不同,1的回调是为了唤起处于等待事件而处于休眠的进程,2的回调是为了将epitem中的rdllink结构增加到ready list中。參考:
http://www.cnblogs.com/apprentice89/archive/2013/05/09/3068274.html http://www.cnblogs.com/apprentice89/p/3234677.html
相关文章推荐
- hdu杭电1702 ACboy needs your help again!【栈和队列】
- Train Problem I
- PAINT和WM_ERASEBKGND消息
- 为什么delegate属性使用assigne而不是retain?
- 220Contains Duplicate III
- Factorial Trailing Zeroes
- hdu-1022 Train Problem I (栈的简单应用)
- HDU-2057 A+B Again
- 绑定远程服务的流程aidl
- HDU 2925 Musical Chairs(约瑟夫环问题)
- Climbing Stairs
- offsetof与container_of宏(个人理解)
- poj3250 Bad Hair Day
- hpu 1022&&nyoj 150 Train Problem I 【栈】
- Container With Most Water
- hdu杭电1002 Train Problem I【栈】
- 杭电1022 Train Problem I
- idea 14 Error: Failed to create a child event loop
- hdu4770Lights Against Dudely 暴力搜索
- hdoj 1789 Doing Homework again