Rev 422 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
422 | giacomo | 1 | /* |
2 | * include/linux/eventpoll.h ( Efficent event polling implementation ) |
||
3 | * Copyright (C) 2001,...,2003 Davide Libenzi |
||
4 | * |
||
5 | * This program is free software; you can redistribute it and/or modify |
||
6 | * it under the terms of the GNU General Public License as published by |
||
7 | * the Free Software Foundation; either version 2 of the License, or |
||
8 | * (at your option) any later version. |
||
9 | * |
||
10 | * Davide Libenzi <davidel@xmailserver.org> |
||
11 | * |
||
12 | */ |
||
13 | |||
14 | #ifndef _LINUX_EVENTPOLL_H |
||
15 | #define _LINUX_EVENTPOLL_H |
||
16 | |||
17 | #include <linux/types.h> |
||
18 | |||
19 | |||
20 | /* Valid opcodes to issue to sys_epoll_ctl() */ |
||
21 | #define EPOLL_CTL_ADD 1 |
||
22 | #define EPOLL_CTL_DEL 2 |
||
23 | #define EPOLL_CTL_MOD 3 |
||
24 | |||
25 | /* Set the Edge Triggered behaviour for the target file descriptor */ |
||
26 | #define EPOLLET (1 << 31) |
||
27 | |||
28 | /* |
||
29 | * On x86-64 make the 64bit structure have the same alignment as the |
||
30 | * 32bit structure. This makes 32bit emulation easier. |
||
31 | */ |
||
32 | #ifdef __x86_64__ |
||
33 | #define EPOLL_PACKED __attribute__((packed)) |
||
34 | #else |
||
35 | #define EPOLL_PACKED |
||
36 | #endif |
||
37 | |||
38 | struct epoll_event { |
||
39 | __u32 events; |
||
40 | __u64 data; |
||
41 | } EPOLL_PACKED; |
||
42 | |||
43 | #ifdef __KERNEL__ |
||
44 | |||
45 | /* Forward declarations to avoid compiler errors */ |
||
46 | struct file; |
||
47 | |||
48 | |||
49 | /* Kernel space functions implementing the user space "epoll" API */ |
||
50 | asmlinkage long sys_epoll_create(int size); |
||
51 | asmlinkage long sys_epoll_ctl(int epfd, int op, int fd, |
||
52 | struct epoll_event __user *event); |
||
53 | asmlinkage long sys_epoll_wait(int epfd, struct epoll_event __user *events, |
||
54 | int maxevents, int timeout); |
||
55 | |||
56 | #ifdef CONFIG_EPOLL |
||
57 | |||
58 | /* Used to initialize the epoll bits inside the "struct file" */ |
||
59 | void eventpoll_init_file(struct file *file); |
||
60 | |||
61 | /* Used to release the epoll bits inside the "struct file" */ |
||
62 | void eventpoll_release_file(struct file *file); |
||
63 | |||
64 | /* |
||
65 | * This is called from inside fs/file_table.c:__fput() to unlink files |
||
66 | * from the eventpoll interface. We need to have this facility to cleanup |
||
67 | * correctly files that are closed without being removed from the eventpoll |
||
68 | * interface. |
||
69 | */ |
||
70 | static inline void eventpoll_release(struct file *file) |
||
71 | { |
||
72 | |||
73 | /* |
||
74 | * Fast check to avoid the get/release of the semaphore. Since |
||
75 | * we're doing this outside the semaphore lock, it might return |
||
76 | * false negatives, but we don't care. It'll help in 99.99% of cases |
||
77 | * to avoid the semaphore lock. False positives simply cannot happen |
||
78 | * because the file in on the way to be removed and nobody ( but |
||
79 | * eventpoll ) has still a reference to this file. |
||
80 | */ |
||
81 | if (likely(list_empty(&file->f_ep_links))) |
||
82 | return; |
||
83 | |||
84 | /* |
||
85 | * The file is being closed while it is still linked to an epoll |
||
86 | * descriptor. We need to handle this by correctly unlinking it |
||
87 | * from its containers. |
||
88 | */ |
||
89 | eventpoll_release_file(file); |
||
90 | } |
||
91 | |||
92 | |||
93 | #else |
||
94 | |||
95 | static inline void eventpoll_init_file(struct file *file) {} |
||
96 | static inline void eventpoll_release(struct file *file) {} |
||
97 | |||
98 | #endif |
||
99 | |||
100 | #endif /* #ifdef __KERNEL__ */ |
||
101 | |||
102 | #endif /* #ifndef _LINUX_EVENTPOLL_H */ |
||
103 |