]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/event.h
Change the way that the queue(3) structures are declared; don't assume that
[FreeBSD/FreeBSD.git] / sys / sys / event.h
1 /*-
2  * Copyright (c) 1999,2000 Jonathan Lemon <jlemon@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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
24  * SUCH DAMAGE.
25  *
26  *      $FreeBSD$
27  */
28
29 #ifndef _SYS_EVENT_H_
30 #define _SYS_EVENT_H_
31
32 #define EVFILT_READ             (-1)
33 #define EVFILT_WRITE            (-2)
34 #define EVFILT_AIO              (-3)    /* attached to aio requests */
35 #define EVFILT_VNODE            (-4)    /* attached to vnodes */
36 #define EVFILT_PROC             (-5)    /* attached to struct proc */
37 #define EVFILT_SIGNAL           (-6)    /* attached to struct proc */
38
39 #define EVFILT_SYSCOUNT         6
40
41 struct kevent {
42         uintptr_t       ident;          /* identifier for this event */
43         short           filter;         /* filter for event */
44         u_short         flags;
45         u_int           fflags;
46         intptr_t        data;
47         void            *udata;         /* opaque user data identifier */
48 };
49
50 /* actions */
51 #define EV_ADD          0x0001          /* add event to kq (implies enable) */
52 #define EV_DELETE       0x0002          /* delete event from kq */
53 #define EV_ENABLE       0x0004          /* enable event */
54 #define EV_DISABLE      0x0008          /* disable event (not reported) */
55
56 /* flags */
57 #define EV_ONESHOT      0x0010          /* only report one occurrence */
58 #define EV_CLEAR        0x0020          /* clear event state after reporting */
59
60 #define EV_SYSFLAGS     0xF000          /* reserved by system */
61 #define EV_FLAG1        0x2000          /* filter-specific flag */
62
63 /* returned values */
64 #define EV_EOF          0x8000          /* EOF detected */
65 #define EV_ERROR        0x4000          /* error, data contains errno */
66
67 /*
68  * data/hint flags for EVFILT_VNODE, shared with userspace
69  */
70 #define NOTE_DELETE     0x0001                  /* vnode was removed */
71 #define NOTE_WRITE      0x0002                  /* data contents changed */
72 #define NOTE_EXTEND     0x0004                  /* size increased */
73 #define NOTE_ATTRIB     0x0008                  /* attributes changed */
74 #define NOTE_LINK       0x0010                  /* link count changed */
75 #define NOTE_RENAME     0x0020                  /* vnode was renamed */
76
77 /*
78  * data/hint flags for EVFILT_PROC, shared with userspace
79  */
80 #define NOTE_EXIT       0x80000000              /* process exited */
81 #define NOTE_FORK       0x40000000              /* process forked */
82 #define NOTE_EXEC       0x20000000              /* process exec'd */
83 #define NOTE_PCTRLMASK  0xf0000000              /* mask for hint bits */
84 #define NOTE_PDATAMASK  0x000fffff              /* mask for pid */
85
86 /* additional flags for EVFILT_PROC */
87 #define NOTE_TRACK      0x00000001              /* follow across forks */
88 #define NOTE_TRACKERR   0x00000002              /* could not track child */
89 #define NOTE_CHILD      0x00000004              /* am a child process */
90
91 /*
92  * This is currently visible to userland to work around broken
93  * programs which pull in <sys/proc.h> or <sys/select.h>.
94  */
95 #include <sys/queue.h> 
96 struct knote;
97 SLIST_HEAD(klist, struct knote);
98
99 #ifdef _KERNEL
100
101 #define KNOTE(list, hint)       if ((list) != NULL) knote(list, hint)
102
103 /*
104  * Flag indicating hint is a signal.  Used by EVFILT_SIGNAL, and also
105  * shared by EVFILT_PROC  (all knotes attached to p->p_klist)
106  */
107 #define NOTE_SIGNAL     0x08000000
108
109 struct filterops {
110         int     f_isfd;         /* true if ident == filedescriptor */
111         int     (*f_attach)     __P((struct knote *kn));
112         void    (*f_detach)     __P((struct knote *kn));
113         int     (*f_event)      __P((struct knote *kn, long hint));
114 };
115
116 struct knote {
117         SLIST_ENTRY(struct knote)       kn_link;        /* for fd */
118         SLIST_ENTRY(struct knote)       kn_selnext;     /* for struct selinfo */
119         TAILQ_ENTRY(struct knote)       kn_tqe;
120         struct                  kqueue *kn_kq;  /* which queue we are on */
121         struct                  kevent kn_kevent;
122         int                     kn_status;
123         int                     kn_sfflags;     /* saved filter flags */
124         intptr_t                kn_sdata;       /* saved data field */
125         union {
126                 struct          file *p_fp;     /* file data pointer */
127                 struct          proc *p_proc;   /* proc pointer */
128         } kn_ptr;
129         struct                  filterops *kn_fop;
130 #define KN_ACTIVE       0x01                    /* event has been triggered */
131 #define KN_QUEUED       0x02                    /* event is on queue */
132 #define KN_DISABLED     0x04                    /* event is disabled */
133 #define KN_DETACHED     0x08                    /* knote is detached */
134
135 #define kn_id           kn_kevent.ident
136 #define kn_filter       kn_kevent.filter
137 #define kn_flags        kn_kevent.flags
138 #define kn_fflags       kn_kevent.fflags
139 #define kn_data         kn_kevent.data
140 #define kn_fp           kn_ptr.p_fp
141 };
142
143 struct proc;
144
145 extern void     knote(struct klist *list, long hint);
146 extern void     knote_remove(struct proc *p, struct klist *list);
147 extern void     knote_fdclose(struct proc *p, int fd);
148 extern int      kqueue_register(struct kqueue *kq,
149                     struct kevent *kev, struct proc *p);
150
151 #else   /* !_KERNEL */
152
153 #include <sys/cdefs.h>
154 struct timespec;
155
156 __BEGIN_DECLS
157 int     kqueue __P((void));
158 int     kevent __P((int kq, int nchanges, struct kevent **changelist,
159                     int nevents, struct kevent *eventlist,
160                     struct timespec *timeout));
161 __END_DECLS
162
163 #endif /* !_KERNEL */
164
165 #endif /* !_SYS_EVENT_H_ */