blob: 41085d0f3955b3ff247b426de9452b731d00c19b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002 * include/linux/eventpoll.h ( Efficient event polling implementation )
Davide Libenzi3419b232006-06-25 05:48:14 -07003 * Copyright (C) 2001,...,2006 Davide Libenzi
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
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
Ulrich Dreppera0998b52008-07-23 21:29:27 -070017/* For O_CLOEXEC */
18#include <linux/fcntl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/types.h>
20
Ulrich Drepper9fe5ad92008-07-23 21:29:43 -070021/* Flags for epoll_create1. */
Ulrich Dreppera0998b52008-07-23 21:29:27 -070022#define EPOLL_CLOEXEC O_CLOEXEC
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24/* Valid opcodes to issue to sys_epoll_ctl() */
25#define EPOLL_CTL_ADD 1
26#define EPOLL_CTL_DEL 2
27#define EPOLL_CTL_MOD 3
Paton J. Lewis03a7beb2012-10-04 17:13:39 -070028#define EPOLL_CTL_DISABLE 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Arve Hjønnevåg4d7e30d2012-05-01 21:33:34 +020030/*
31 * Request the handling of system wakeup events so as to prevent system suspends
32 * from happening while those events are being processed.
33 *
34 * Assuming neither EPOLLET nor EPOLLONESHOT is set, system suspends will not be
35 * re-allowed until epoll_wait is called again after consuming the wakeup
36 * event(s).
37 *
Michael Kerriskd9914cf2012-07-17 21:37:27 +020038 * Requires CAP_BLOCK_SUSPEND
Arve Hjønnevåg4d7e30d2012-05-01 21:33:34 +020039 */
40#define EPOLLWAKEUP (1 << 29)
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042/* Set the One Shot behaviour for the target file descriptor */
43#define EPOLLONESHOT (1 << 30)
44
45/* Set the Edge Triggered behaviour for the target file descriptor */
46#define EPOLLET (1 << 31)
47
48/*
49 * On x86-64 make the 64bit structure have the same alignment as the
50 * 32bit structure. This makes 32bit emulation easier.
Jeff Diked75e26a2007-03-26 21:32:20 -080051 *
Al Viroca5cd872007-10-29 04:31:16 +000052 * UML/x86_64 needs the same packing as x86_64
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 */
54#ifdef __x86_64__
55#define EPOLL_PACKED __attribute__((packed))
56#else
57#define EPOLL_PACKED
58#endif
59
60struct epoll_event {
61 __u32 events;
62 __u64 data;
63} EPOLL_PACKED;
64
65#ifdef __KERNEL__
66
67/* Forward declarations to avoid compiler errors */
68struct file;
69
70
71#ifdef CONFIG_EPOLL
72
73/* Used to initialize the epoll bits inside the "struct file" */
Benjamin LaHaise5a6b7952006-03-23 03:01:03 -080074static inline void eventpoll_init_file(struct file *file)
75{
76 INIT_LIST_HEAD(&file->f_ep_links);
Jason Baron28d82dc2012-01-12 17:17:43 -080077 INIT_LIST_HEAD(&file->f_tfile_llink);
Benjamin LaHaise5a6b7952006-03-23 03:01:03 -080078}
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81/* Used to release the epoll bits inside the "struct file" */
82void eventpoll_release_file(struct file *file);
83
84/*
85 * This is called from inside fs/file_table.c:__fput() to unlink files
86 * from the eventpoll interface. We need to have this facility to cleanup
87 * correctly files that are closed without being removed from the eventpoll
88 * interface.
89 */
90static inline void eventpoll_release(struct file *file)
91{
92
93 /*
94 * Fast check to avoid the get/release of the semaphore. Since
95 * we're doing this outside the semaphore lock, it might return
96 * false negatives, but we don't care. It'll help in 99.99% of cases
97 * to avoid the semaphore lock. False positives simply cannot happen
98 * because the file in on the way to be removed and nobody ( but
99 * eventpoll ) has still a reference to this file.
100 */
101 if (likely(list_empty(&file->f_ep_links)))
102 return;
103
104 /*
105 * The file is being closed while it is still linked to an epoll
106 * descriptor. We need to handle this by correctly unlinking it
107 * from its containers.
108 */
109 eventpoll_release_file(file);
110}
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#else
113
114static inline void eventpoll_init_file(struct file *file) {}
115static inline void eventpoll_release(struct file *file) {}
116
117#endif
118
119#endif /* #ifdef __KERNEL__ */
120
121#endif /* #ifndef _LINUX_EVENTPOLL_H */
122