Blame view

include/linux/eventpoll.h 2.87 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
  /*
   *  include/linux/eventpoll.h ( Efficent event polling implementation )
3419b23a9   Davide Libenzi   [PATCH] epoll: us...
3
   *  Copyright (C) 2001,...,2006	 Davide Libenzi
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
   *
   *  This program is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation; either version 2 of the License, or
   *  (at your option) any later version.
   *
   *  Davide Libenzi <davidel@xmailserver.org>
   *
   */
  
  #ifndef _LINUX_EVENTPOLL_H
  #define _LINUX_EVENTPOLL_H
  
  #include <linux/types.h>
  
  
  /* Valid opcodes to issue to sys_epoll_ctl() */
  #define EPOLL_CTL_ADD 1
  #define EPOLL_CTL_DEL 2
  #define EPOLL_CTL_MOD 3
  
  /* Set the One Shot behaviour for the target file descriptor */
  #define EPOLLONESHOT (1 << 30)
  
  /* Set the Edge Triggered behaviour for the target file descriptor */
  #define EPOLLET (1 << 31)
  
  /* 
   * On x86-64 make the 64bit structure have the same alignment as the
   * 32bit structure. This makes 32bit emulation easier.
d75e26a82   Jeff Dike   [PATCH] uml: fix ...
34
35
36
   *
   * UML/x86_64 needs the same packing as x86_64 - UML + UML_X86 +
   * 64_BIT adds up to UML/x86_64.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
39
40
   */
  #ifdef __x86_64__
  #define EPOLL_PACKED __attribute__((packed))
  #else
d75e26a82   Jeff Dike   [PATCH] uml: fix ...
41
42
43
  #if defined(CONFIG_UML) && defined(CONFIG_UML_X86) && defined(CONFIG_64BIT)
  #define EPOLL_PACKED __attribute__((packed))
  #else
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
45
  #define EPOLL_PACKED
  #endif
d75e26a82   Jeff Dike   [PATCH] uml: fix ...
46
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  
  struct epoll_event {
  	__u32 events;
  	__u64 data;
  } EPOLL_PACKED;
  
  #ifdef __KERNEL__
  
  /* Forward declarations to avoid compiler errors */
  struct file;
  
  
  #ifdef CONFIG_EPOLL
  
  /* Used to initialize the epoll bits inside the "struct file" */
5a6b7951b   Benjamin LaHaise   [PATCH] get_empty...
62
63
64
65
66
  static inline void eventpoll_init_file(struct file *file)
  {
  	INIT_LIST_HEAD(&file->f_ep_links);
  	spin_lock_init(&file->f_ep_lock);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  
  /* Used to release the epoll bits inside the "struct file" */
  void eventpoll_release_file(struct file *file);
  
  /*
   * This is called from inside fs/file_table.c:__fput() to unlink files
   * from the eventpoll interface. We need to have this facility to cleanup
   * correctly files that are closed without being removed from the eventpoll
   * interface.
   */
  static inline void eventpoll_release(struct file *file)
  {
  
  	/*
  	 * Fast check to avoid the get/release of the semaphore. Since
  	 * we're doing this outside the semaphore lock, it might return
  	 * false negatives, but we don't care. It'll help in 99.99% of cases
  	 * to avoid the semaphore lock. False positives simply cannot happen
  	 * because the file in on the way to be removed and nobody ( but
  	 * eventpoll ) has still a reference to this file.
  	 */
  	if (likely(list_empty(&file->f_ep_links)))
  		return;
  
  	/*
  	 * The file is being closed while it is still linked to an epoll
  	 * descriptor. We need to handle this by correctly unlinking it
  	 * from its containers.
  	 */
  	eventpoll_release_file(file);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98
99
100
101
102
103
104
105
106
107
  #else
  
  static inline void eventpoll_init_file(struct file *file) {}
  static inline void eventpoll_release(struct file *file) {}
  
  #endif
  
  #endif /* #ifdef __KERNEL__ */
  
  #endif /* #ifndef _LINUX_EVENTPOLL_H */