eventfd.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * include/linux/eventfd.h
  4. *
  5. * Copyright (C) 2007 Davide Libenzi <[email protected]>
  6. *
  7. */
  8. #ifndef _LINUX_EVENTFD_H
  9. #define _LINUX_EVENTFD_H
  10. #include <linux/fcntl.h>
  11. #include <linux/wait.h>
  12. #include <linux/err.h>
  13. #include <linux/percpu-defs.h>
  14. #include <linux/percpu.h>
  15. #include <linux/sched.h>
  16. /*
  17. * CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining
  18. * new flags, since they might collide with O_* ones. We want
  19. * to re-use O_* flags that couldn't possibly have a meaning
  20. * from eventfd, in order to leave a free define-space for
  21. * shared O_* flags.
  22. */
  23. #define EFD_SEMAPHORE (1 << 0)
  24. #define EFD_CLOEXEC O_CLOEXEC
  25. #define EFD_NONBLOCK O_NONBLOCK
  26. #define EFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
  27. #define EFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE)
  28. struct eventfd_ctx;
  29. struct file;
  30. #ifdef CONFIG_EVENTFD
  31. void eventfd_ctx_put(struct eventfd_ctx *ctx);
  32. struct file *eventfd_fget(int fd);
  33. struct eventfd_ctx *eventfd_ctx_fdget(int fd);
  34. struct eventfd_ctx *eventfd_ctx_fileget(struct file *file);
  35. __u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n);
  36. __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, unsigned mask);
  37. int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t *wait,
  38. __u64 *cnt);
  39. void eventfd_ctx_do_read(struct eventfd_ctx *ctx, __u64 *cnt);
  40. static inline bool eventfd_signal_allowed(void)
  41. {
  42. return !current->in_eventfd;
  43. }
  44. #else /* CONFIG_EVENTFD */
  45. /*
  46. * Ugly ugly ugly error layer to support modules that uses eventfd but
  47. * pretend to work in !CONFIG_EVENTFD configurations. Namely, AIO.
  48. */
  49. static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd)
  50. {
  51. return ERR_PTR(-ENOSYS);
  52. }
  53. static inline int eventfd_signal(struct eventfd_ctx *ctx, __u64 n)
  54. {
  55. return -ENOSYS;
  56. }
  57. static inline int eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n,
  58. unsigned mask)
  59. {
  60. return -ENOSYS;
  61. }
  62. static inline void eventfd_ctx_put(struct eventfd_ctx *ctx)
  63. {
  64. }
  65. static inline int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx,
  66. wait_queue_entry_t *wait, __u64 *cnt)
  67. {
  68. return -ENOSYS;
  69. }
  70. static inline bool eventfd_signal_allowed(void)
  71. {
  72. return true;
  73. }
  74. static inline void eventfd_ctx_do_read(struct eventfd_ctx *ctx, __u64 *cnt)
  75. {
  76. }
  77. #endif
  78. #endif /* _LINUX_EVENTFD_H */