免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2082 | 回复: 0
打印 上一主题 下一主题

introduction of kqueue/kevent [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-05-03 00:05 |只看该作者 |倒序浏览

                Here is a brief introduction about kqueue/kevent mechanism in FreeBSD. It is just my note. The Operating System I use during this note.
[amd64box:~]$uname -a
FreeBSD amd64box 6.2-RELEASE FreeBSD 6.2-RELEASE #0: Mon Apr 23 21:42:50 CST 2007     root@:/usr/src/sys/amd64/compile/AMD64MP  amd64
A kqueue is a container of state for kevent calls.
     int     kevent(int kq, const struct kevent *changelist, int nchanges,
/* register these kevents on this kqueue */         struct kevent *eventlist, int nevents,
/* get ready kevents from this kqueue */         const struct timespec *timeout);
A kqueue dispatches those kevents in changelist to files they point to, and he knows which ones have been dispatched or not. Every file will report to this kqueue if its status changed (if this kqueue is interested in it). The kqueue will keep these reports and send them to user via kevent when requested.
kqueue_register     tell the kqueue to dispatch this kevent (called knote in kernel) to corresponding file, and kqueue will keep this kevent in a private list, so that there are at most one (ident, filter) in one kqueue for any ident and/or filter.
kqueue_scan         scan the pending kevents on a kqueue if any and msleep on it if there are no kevents pending on the kqueue
KNOTE_ACTIVATE      a kevent is triggered. Insert the kevent into its kqueue's list and tell any monitor that the kqueue is OK. to avoid deadlock, use taskqueue to activate kevents on si_note asynchronously.
This is a common scene.
A registers kevents kev0, kev1 on a kqueue kq1, kq1 dispatches these kevents to files f0, f1, and A msleeps on kq1. B triggers kev0, puts kev0 on the active list of kq1 and wakeups A from kq1 asynchronously. A finds that kev0 is triggered and returns to user mode.
Locks
KQ_LOCK     protects the kqueue and knotes on it.
kq_global    acquired if we need lock multiple kqueues
KN_INFLUX    protects a knote when its kqueue is unlocked
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/10543/showart_290779.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP