2 * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/sys/kern/kern_event.c,v 1.2.2.10 2004/04/04 07:03:14 cperciva Exp $
27 * $DragonFly: src/sys/kern/kern_event.c,v 1.30 2006/09/19 11:47:35 corecode Exp $
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
34 #include <sys/malloc.h>
35 #include <sys/unistd.h>
38 #include <sys/fcntl.h>
39 #include <sys/select.h>
40 #include <sys/queue.h>
41 #include <sys/event.h>
42 #include <sys/eventvar.h>
44 #include <sys/protosw.h>
45 #include <sys/socket.h>
46 #include <sys/socketvar.h>
48 #include <sys/sysctl.h>
49 #include <sys/sysproto.h>
51 #include <sys/thread2.h>
52 #include <sys/file2.h>
54 #include <vm/vm_zone.h>
56 MALLOC_DEFINE(M_KQUEUE, "kqueue", "memory for kqueue system");
58 static int kqueue_scan(struct file *fp, int maxevents,
59 struct kevent *ulistp, const struct timespec *timeout,
60 struct thread *td, int *res);
61 static int kqueue_read(struct file *fp, struct uio *uio,
62 struct ucred *cred, int flags);
63 static int kqueue_write(struct file *fp, struct uio *uio,
64 struct ucred *cred, int flags);
65 static int kqueue_ioctl(struct file *fp, u_long com, caddr_t data,
67 static int kqueue_poll(struct file *fp, int events, struct ucred *cred);
68 static int kqueue_kqfilter(struct file *fp, struct knote *kn);
69 static int kqueue_stat(struct file *fp, struct stat *st,
71 static int kqueue_close(struct file *fp);
72 static void kqueue_wakeup(struct kqueue *kq);
77 static struct fileops kqueueops = {
78 .fo_read = kqueue_read,
79 .fo_write = kqueue_write,
80 .fo_ioctl = kqueue_ioctl,
81 .fo_poll = kqueue_poll,
82 .fo_kqfilter = kqueue_kqfilter,
83 .fo_stat = kqueue_stat,
84 .fo_close = kqueue_close,
85 .fo_shutdown = nofo_shutdown
88 static void knote_attach(struct knote *kn, struct filedesc *fdp);
89 static void knote_drop(struct knote *kn, struct thread *td);
90 static void knote_enqueue(struct knote *kn);
91 static void knote_dequeue(struct knote *kn);
92 static void knote_init(void);
93 static struct knote *knote_alloc(void);
94 static void knote_free(struct knote *kn);
96 static void filt_kqdetach(struct knote *kn);
97 static int filt_kqueue(struct knote *kn, long hint);
98 static int filt_procattach(struct knote *kn);
99 static void filt_procdetach(struct knote *kn);
100 static int filt_proc(struct knote *kn, long hint);
101 static int filt_fileattach(struct knote *kn);
102 static void filt_timerexpire(void *knx);
103 static int filt_timerattach(struct knote *kn);
104 static void filt_timerdetach(struct knote *kn);
105 static int filt_timer(struct knote *kn, long hint);
107 static struct filterops file_filtops =
108 { 1, filt_fileattach, NULL, NULL };
109 static struct filterops kqread_filtops =
110 { 1, NULL, filt_kqdetach, filt_kqueue };
111 static struct filterops proc_filtops =
112 { 0, filt_procattach, filt_procdetach, filt_proc };
113 static struct filterops timer_filtops =
114 { 0, filt_timerattach, filt_timerdetach, filt_timer };
116 static vm_zone_t knote_zone;
117 static int kq_ncallouts = 0;
118 static int kq_calloutmax = (4 * 1024);
119 SYSCTL_INT(_kern, OID_AUTO, kq_calloutmax, CTLFLAG_RW,
120 &kq_calloutmax, 0, "Maximum number of callouts allocated for kqueue");
122 #define KNOTE_ACTIVATE(kn) do { \
123 kn->kn_status |= KN_ACTIVE; \
124 if ((kn->kn_status & (KN_QUEUED | KN_DISABLED)) == 0) \
128 #define KN_HASHSIZE 64 /* XXX should be tunable */
129 #define KN_HASH(val, mask) (((val) ^ (val >> 8)) & (mask))
131 extern struct filterops aio_filtops;
132 extern struct filterops sig_filtops;
135 * Table for for all system-defined filters.
137 static struct filterops *sysfilt_ops[] = {
138 &file_filtops, /* EVFILT_READ */
139 &file_filtops, /* EVFILT_WRITE */
140 &aio_filtops, /* EVFILT_AIO */
141 &file_filtops, /* EVFILT_VNODE */
142 &proc_filtops, /* EVFILT_PROC */
143 &sig_filtops, /* EVFILT_SIGNAL */
144 &timer_filtops, /* EVFILT_TIMER */
148 filt_fileattach(struct knote *kn)
150 return (fo_kqfilter(kn->kn_fp, kn));
154 * MPALMOSTSAFE - acquires mplock
157 kqueue_kqfilter(struct file *fp, struct knote *kn)
159 struct kqueue *kq = (struct kqueue *)kn->kn_fp->f_data;
162 if (kn->kn_filter != EVFILT_READ) {
167 kn->kn_fop = &kqread_filtops;
168 SLIST_INSERT_HEAD(&kq->kq_sel.si_note, kn, kn_selnext);
174 filt_kqdetach(struct knote *kn)
176 struct kqueue *kq = (struct kqueue *)kn->kn_fp->f_data;
178 SLIST_REMOVE(&kq->kq_sel.si_note, kn, knote, kn_selnext);
183 filt_kqueue(struct knote *kn, long hint)
185 struct kqueue *kq = (struct kqueue *)kn->kn_fp->f_data;
187 kn->kn_data = kq->kq_count;
188 return (kn->kn_data > 0);
192 filt_procattach(struct knote *kn)
198 p = pfind(kn->kn_id);
199 if (p == NULL && (kn->kn_sfflags & NOTE_EXIT)) {
200 p = zpfind(kn->kn_id);
205 if (! PRISON_CHECK(curproc->p_ucred, p->p_ucred))
208 kn->kn_ptr.p_proc = p;
209 kn->kn_flags |= EV_CLEAR; /* automatically set */
212 * internal flag indicating registration done by kernel
214 if (kn->kn_flags & EV_FLAG1) {
215 kn->kn_data = kn->kn_sdata; /* ppid */
216 kn->kn_fflags = NOTE_CHILD;
217 kn->kn_flags &= ~EV_FLAG1;
220 /* XXX lock the proc here while adding to the list? */
221 SLIST_INSERT_HEAD(&p->p_klist, kn, kn_selnext);
224 * Immediately activate any exit notes if the target process is a
225 * zombie. This is necessary to handle the case where the target
226 * process, e.g. a child, dies before the kevent is registered.
228 if (immediate && filt_proc(kn, NOTE_EXIT))
235 * The knote may be attached to a different process, which may exit,
236 * leaving nothing for the knote to be attached to. So when the process
237 * exits, the knote is marked as DETACHED and also flagged as ONESHOT so
238 * it will be deleted when read out. However, as part of the knote deletion,
239 * this routine is called, so a check is needed to avoid actually performing
240 * a detach, because the original process does not exist any more.
243 filt_procdetach(struct knote *kn)
245 struct proc *p = kn->kn_ptr.p_proc;
247 if (kn->kn_status & KN_DETACHED)
250 /* XXX locking? this might modify another process. */
251 SLIST_REMOVE(&p->p_klist, kn, knote, kn_selnext);
255 filt_proc(struct knote *kn, long hint)
260 * mask off extra data
262 event = (u_int)hint & NOTE_PCTRLMASK;
265 * if the user is interested in this event, record it.
267 if (kn->kn_sfflags & event)
268 kn->kn_fflags |= event;
271 * process is gone, so flag the event as finished.
273 if (event == NOTE_EXIT) {
274 kn->kn_status |= KN_DETACHED;
275 kn->kn_flags |= (EV_EOF | EV_ONESHOT);
280 * process forked, and user wants to track the new process,
281 * so attach a new knote to it, and immediately report an
282 * event with the parent's pid.
284 if ((event == NOTE_FORK) && (kn->kn_sfflags & NOTE_TRACK)) {
289 * register knote with new process.
291 kev.ident = hint & NOTE_PDATAMASK; /* pid */
292 kev.filter = kn->kn_filter;
293 kev.flags = kn->kn_flags | EV_ADD | EV_ENABLE | EV_FLAG1;
294 kev.fflags = kn->kn_sfflags;
295 kev.data = kn->kn_id; /* parent */
296 kev.udata = kn->kn_kevent.udata; /* preserve udata */
297 error = kqueue_register(kn->kn_kq, &kev, NULL);
299 kn->kn_fflags |= NOTE_TRACKERR;
302 return (kn->kn_fflags != 0);
306 filt_timerexpire(void *knx)
308 struct knote *kn = knx;
309 struct callout *calloutp;
316 if ((kn->kn_flags & EV_ONESHOT) == 0) {
317 tv.tv_sec = kn->kn_sdata / 1000;
318 tv.tv_usec = (kn->kn_sdata % 1000) * 1000;
319 tticks = tvtohz_high(&tv);
320 calloutp = (struct callout *)kn->kn_hook;
321 callout_reset(calloutp, tticks, filt_timerexpire, kn);
326 * data contains amount of time to sleep, in milliseconds
329 filt_timerattach(struct knote *kn)
331 struct callout *calloutp;
335 if (kq_ncallouts >= kq_calloutmax)
339 tv.tv_sec = kn->kn_sdata / 1000;
340 tv.tv_usec = (kn->kn_sdata % 1000) * 1000;
341 tticks = tvtohz_high(&tv);
343 kn->kn_flags |= EV_CLEAR; /* automatically set */
344 MALLOC(calloutp, struct callout *, sizeof(*calloutp),
346 callout_init(calloutp);
347 kn->kn_hook = (caddr_t)calloutp;
348 callout_reset(calloutp, tticks, filt_timerexpire, kn);
354 filt_timerdetach(struct knote *kn)
356 struct callout *calloutp;
358 calloutp = (struct callout *)kn->kn_hook;
359 callout_stop(calloutp);
360 FREE(calloutp, M_KQUEUE);
365 filt_timer(struct knote *kn, long hint)
368 return (kn->kn_data != 0);
372 sys_kqueue(struct kqueue_args *uap)
374 struct proc *p = curproc;
375 struct filedesc *fdp = p->p_fd;
380 error = falloc(p, &fp, &fd);
383 fp->f_flag = FREAD | FWRITE;
384 fp->f_type = DTYPE_KQUEUE;
385 fp->f_ops = &kqueueops;
387 kq = kmalloc(sizeof(struct kqueue), M_KQUEUE, M_WAITOK | M_ZERO);
388 TAILQ_INIT(&kq->kq_head);
393 uap->sysmsg_result = fd;
399 sys_kevent(struct kevent_args *uap)
401 struct thread *td = curthread;
402 struct proc *p = td->td_proc;
405 struct file *fp = NULL;
407 int i, n, nerrors, error;
411 fp = holdfp(p->p_fd, uap->fd, -1);
414 if (fp->f_type != DTYPE_KQUEUE) {
419 if (uap->timeout != NULL) {
420 error = copyin(uap->timeout, &ts, sizeof(ts));
426 kq = (struct kqueue *)fp->f_data;
429 while (uap->nchanges > 0) {
430 n = uap->nchanges > KQ_NEVENTS ? KQ_NEVENTS : uap->nchanges;
431 error = copyin(uap->changelist, kq->kq_kev,
432 n * sizeof(struct kevent));
435 for (i = 0; i < n; i++) {
436 kevp = &kq->kq_kev[i];
437 kevp->flags &= ~EV_SYSFLAGS;
438 error = kqueue_register(kq, kevp, td);
440 if (uap->nevents != 0) {
441 kevp->flags = EV_ERROR;
443 (void) copyout((caddr_t)kevp,
444 (caddr_t)uap->eventlist,
455 uap->changelist += n;
458 uap->sysmsg_result = nerrors;
463 error = kqueue_scan(fp, uap->nevents, uap->eventlist, uap->timeout, td, &uap->sysmsg_result);
471 kqueue_register(struct kqueue *kq, struct kevent *kev, struct thread *td)
473 struct filedesc *fdp = kq->kq_fdp;
474 struct filterops *fops;
475 struct file *fp = NULL;
476 struct knote *kn = NULL;
479 if (kev->filter < 0) {
480 if (kev->filter + EVFILT_SYSCOUNT < 0)
482 fops = sysfilt_ops[~kev->filter]; /* to 0-base index */
486 * filter attach routine is responsible for insuring that
487 * the identifier can be attached to it.
489 printf("unknown filter: %d\n", kev->filter);
494 /* validate descriptor */
495 fp = holdfp(fdp, kev->ident, -1);
499 if (kev->ident < fdp->fd_knlistsize) {
500 SLIST_FOREACH(kn, &fdp->fd_knlist[kev->ident], kn_link)
501 if (kq == kn->kn_kq &&
502 kev->filter == kn->kn_filter)
506 if (fdp->fd_knhashmask != 0) {
509 list = &fdp->fd_knhash[
510 KN_HASH((u_long)kev->ident, fdp->fd_knhashmask)];
511 SLIST_FOREACH(kn, list, kn_link)
512 if (kev->ident == kn->kn_id &&
514 kev->filter == kn->kn_filter)
519 if (kn == NULL && ((kev->flags & EV_ADD) == 0)) {
525 * kn now contains the matching knote, or NULL if no match
527 if (kev->flags & EV_ADD) {
540 * apply reference count to knote structure, and
541 * do not release it at the end of this routine.
545 kn->kn_sfflags = kev->fflags;
546 kn->kn_sdata = kev->data;
549 kn->kn_kevent = *kev;
551 knote_attach(kn, fdp);
552 if ((error = fops->f_attach(kn)) != 0) {
558 * The user may change some filter values after the
559 * initial EV_ADD, but doing so will not reset any
560 * filter which have already been triggered.
562 kn->kn_sfflags = kev->fflags;
563 kn->kn_sdata = kev->data;
564 kn->kn_kevent.udata = kev->udata;
568 if (kn->kn_fop->f_event(kn, 0))
571 } else if (kev->flags & EV_DELETE) {
572 kn->kn_fop->f_detach(kn);
577 if ((kev->flags & EV_DISABLE) &&
578 ((kn->kn_status & KN_DISABLED) == 0)) {
580 kn->kn_status |= KN_DISABLED;
584 if ((kev->flags & EV_ENABLE) && (kn->kn_status & KN_DISABLED)) {
586 kn->kn_status &= ~KN_DISABLED;
587 if ((kn->kn_status & KN_ACTIVE) &&
588 ((kn->kn_status & KN_QUEUED) == 0))
600 kqueue_scan(struct file *fp, int maxevents, struct kevent *ulistp,
601 const struct timespec *tsp, struct thread *td, int *res)
603 struct kqueue *kq = (struct kqueue *)fp->f_data;
605 struct timeval atv, rtv, ttv;
606 struct knote *kn, marker;
607 int count, timeout, nkev = 0, error = 0;
614 TIMESPEC_TO_TIMEVAL(&atv, tsp);
615 if (itimerfix(&atv)) {
619 if (tsp->tv_sec == 0 && tsp->tv_nsec == 0)
622 timeout = atv.tv_sec > 24 * 60 * 60 ?
623 24 * 60 * 60 * hz : tvtohz_high(&atv);
624 getmicrouptime(&rtv);
625 timevaladd(&atv, &rtv);
634 if (atv.tv_sec || atv.tv_usec) {
635 getmicrouptime(&rtv);
636 if (timevalcmp(&rtv, &atv, >=))
639 timevalsub(&ttv, &rtv);
640 timeout = ttv.tv_sec > 24 * 60 * 60 ?
641 24 * 60 * 60 * hz : tvtohz_high(&ttv);
647 if (kq->kq_count == 0) {
651 kq->kq_state |= KQ_SLEEP;
652 error = tsleep(kq, PCATCH, "kqread", timeout);
657 /* don't restart after signals... */
658 if (error == ERESTART)
660 else if (error == EWOULDBLOCK)
665 TAILQ_INSERT_TAIL(&kq->kq_head, &marker, kn_tqe);
667 kn = TAILQ_FIRST(&kq->kq_head);
668 TAILQ_REMOVE(&kq->kq_head, kn, kn_tqe);
671 if (count == maxevents)
675 if (kn->kn_status & KN_DISABLED) {
676 kn->kn_status &= ~KN_QUEUED;
680 if ((kn->kn_flags & EV_ONESHOT) == 0 &&
681 kn->kn_fop->f_event(kn, 0) == 0) {
682 kn->kn_status &= ~(KN_QUEUED | KN_ACTIVE);
686 *kevp = kn->kn_kevent;
689 if (kn->kn_flags & EV_ONESHOT) {
690 kn->kn_status &= ~KN_QUEUED;
693 kn->kn_fop->f_detach(kn);
696 } else if (kn->kn_flags & EV_CLEAR) {
699 kn->kn_status &= ~(KN_QUEUED | KN_ACTIVE);
702 TAILQ_INSERT_TAIL(&kq->kq_head, kn, kn_tqe);
705 if (nkev == KQ_NEVENTS) {
707 error = copyout((caddr_t)&kq->kq_kev, (caddr_t)ulistp,
708 sizeof(struct kevent) * nkev);
717 TAILQ_REMOVE(&kq->kq_head, &marker, kn_tqe);
721 error = copyout((caddr_t)&kq->kq_kev, (caddr_t)ulistp,
722 sizeof(struct kevent) * nkev);
723 *res = maxevents - count;
729 * This could be expanded to call kqueue_scan, if desired.
734 kqueue_read(struct file *fp, struct uio *uio, struct ucred *cred, int flags)
743 kqueue_write(struct file *fp, struct uio *uio, struct ucred *cred, int flags)
752 kqueue_ioctl(struct file *fp, u_long com, caddr_t data, struct ucred *cred)
758 * MPALMOSTSAFE - acquires mplock
761 kqueue_poll(struct file *fp, int events, struct ucred *cred)
763 struct kqueue *kq = (struct kqueue *)fp->f_data;
768 if (events & (POLLIN | POLLRDNORM)) {
770 revents |= events & (POLLIN | POLLRDNORM);
772 selrecord(curthread, &kq->kq_sel);
773 kq->kq_state |= KQ_SEL;
785 kqueue_stat(struct file *fp, struct stat *st, struct ucred *cred)
787 struct kqueue *kq = (struct kqueue *)fp->f_data;
789 bzero((void *)st, sizeof(*st));
790 st->st_size = kq->kq_count;
791 st->st_blksize = sizeof(struct kevent);
792 st->st_mode = S_IFIFO;
797 * MPALMOSTSAFE - acquires mplock
800 kqueue_close(struct file *fp)
802 struct thread *td = curthread;
803 struct proc *p = td->td_proc;
804 struct kqueue *kq = (struct kqueue *)fp->f_data;
805 struct filedesc *fdp;
806 struct knote **knp, *kn, *kn0;
812 for (i = 0; i < fdp->fd_knlistsize; i++) {
813 knp = &SLIST_FIRST(&fdp->fd_knlist[i]);
816 kn0 = SLIST_NEXT(kn, kn_link);
817 if (kq == kn->kn_kq) {
818 kn->kn_fop->f_detach(kn);
823 knp = &SLIST_NEXT(kn, kn_link);
828 if (fdp->fd_knhashmask != 0) {
829 for (i = 0; i < fdp->fd_knhashmask + 1; i++) {
830 knp = &SLIST_FIRST(&fdp->fd_knhash[i]);
833 kn0 = SLIST_NEXT(kn, kn_link);
834 if (kq == kn->kn_kq) {
835 kn->kn_fop->f_detach(kn);
836 /* XXX non-fd release of kn->kn_ptr */
840 knp = &SLIST_NEXT(kn, kn_link);
854 kqueue_wakeup(struct kqueue *kq)
856 if (kq->kq_state & KQ_SLEEP) {
857 kq->kq_state &= ~KQ_SLEEP;
860 if (kq->kq_state & KQ_SEL) {
861 kq->kq_state &= ~KQ_SEL;
862 selwakeup(&kq->kq_sel);
864 KNOTE(&kq->kq_sel.si_note, 0);
868 * walk down a list of knotes, activating them if their event has triggered.
871 knote(struct klist *list, long hint)
875 SLIST_FOREACH(kn, list, kn_selnext)
876 if (kn->kn_fop->f_event(kn, hint))
881 * remove all knotes from a specified klist
884 knote_remove(struct thread *td, struct klist *list)
888 while ((kn = SLIST_FIRST(list)) != NULL) {
889 kn->kn_fop->f_detach(kn);
895 * remove all knotes referencing a specified fd
898 knote_fdclose(struct proc *p, int fd)
900 struct filedesc *fdp = p->p_fd;
901 struct klist *list = &fdp->fd_knlist[fd];
902 /* Take any thread of p */
903 struct thread *td = LIST_FIRST(&p->p_lwps)->lwp_thread;
905 knote_remove(td, list);
909 knote_attach(struct knote *kn, struct filedesc *fdp)
914 if (! kn->kn_fop->f_isfd) {
915 if (fdp->fd_knhashmask == 0)
916 fdp->fd_knhash = hashinit(KN_HASHSIZE, M_KQUEUE,
917 &fdp->fd_knhashmask);
918 list = &fdp->fd_knhash[KN_HASH(kn->kn_id, fdp->fd_knhashmask)];
922 if (fdp->fd_knlistsize <= kn->kn_id) {
923 size = fdp->fd_knlistsize;
924 while (size <= kn->kn_id)
926 MALLOC(list, struct klist *,
927 size * sizeof(struct klist *), M_KQUEUE, M_WAITOK);
928 bcopy((caddr_t)fdp->fd_knlist, (caddr_t)list,
929 fdp->fd_knlistsize * sizeof(struct klist *));
930 bzero((caddr_t)list +
931 fdp->fd_knlistsize * sizeof(struct klist *),
932 (size - fdp->fd_knlistsize) * sizeof(struct klist *));
933 if (fdp->fd_knlist != NULL)
934 FREE(fdp->fd_knlist, M_KQUEUE);
935 fdp->fd_knlistsize = size;
936 fdp->fd_knlist = list;
938 list = &fdp->fd_knlist[kn->kn_id];
940 SLIST_INSERT_HEAD(list, kn, kn_link);
945 * should be called outside of a critical section, since we don't want to
946 * hold a critical section while calling fdrop and free.
949 knote_drop(struct knote *kn, struct thread *td)
951 struct filedesc *fdp;
954 KKASSERT(td->td_proc);
955 fdp = td->td_proc->p_fd;
956 if (kn->kn_fop->f_isfd)
957 list = &fdp->fd_knlist[kn->kn_id];
959 list = &fdp->fd_knhash[KN_HASH(kn->kn_id, fdp->fd_knhashmask)];
961 SLIST_REMOVE(list, kn, knote, kn_link);
962 if (kn->kn_status & KN_QUEUED)
964 if (kn->kn_fop->f_isfd)
971 knote_enqueue(struct knote *kn)
973 struct kqueue *kq = kn->kn_kq;
976 KASSERT((kn->kn_status & KN_QUEUED) == 0, ("knote already queued"));
978 TAILQ_INSERT_TAIL(&kq->kq_head, kn, kn_tqe);
979 kn->kn_status |= KN_QUEUED;
986 knote_dequeue(struct knote *kn)
988 struct kqueue *kq = kn->kn_kq;
990 KASSERT(kn->kn_status & KN_QUEUED, ("knote not queued"));
993 TAILQ_REMOVE(&kq->kq_head, kn, kn_tqe);
994 kn->kn_status &= ~KN_QUEUED;
1002 knote_zone = zinit("KNOTE", sizeof(struct knote), 0, 0, 1);
1004 SYSINIT(knote, SI_SUB_PSEUDO, SI_ORDER_ANY, knote_init, NULL)
1006 static struct knote *
1009 return ((struct knote *)zalloc(knote_zone));
1013 knote_free(struct knote *kn)
1015 zfree(knote_zone, kn);