eventfd.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * include/linux/eventfd.h
  4. *
  5. * Copyright (C) 2007 Davide Libenzi <davidel@xmailserver.org>
  6. *
  7. */
  8. #ifndef _LINUX_EVENTFD_H
  9. #define _LINUX_EVENTFD_H
  10. #include <linux/fcntl.h>
  11. #include <linux/wait.h>
  12. /*
  13. * CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining
  14. * new flags, since they might collide with O_* ones. We want
  15. * to re-use O_* flags that couldn't possibly have a meaning
  16. * from eventfd, in order to leave a free define-space for
  17. * shared O_* flags.
  18. */
  19. #define EFD_SEMAPHORE (1 << 0)
  20. #define EFD_CLOEXEC O_CLOEXEC
  21. #define EFD_NONBLOCK O_NONBLOCK
  22. #define EFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
  23. #define EFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE)
  24. struct eventfd_ctx;
  25. struct file;
  26. #ifdef CONFIG_EVENTFD
  27. void eventfd_ctx_put(struct eventfd_ctx *ctx);
  28. struct file *eventfd_fget(int fd);
  29. struct eventfd_ctx *eventfd_ctx_fdget(int fd);
  30. struct eventfd_ctx *eventfd_ctx_fileget(struct file *file);
  31. __u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n);
  32. int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t *wait,
  33. __u64 *cnt);
  34. #else /* CONFIG_EVENTFD */
  35. /*
  36. * Ugly ugly ugly error layer to support modules that uses eventfd but
  37. * pretend to work in !CONFIG_EVENTFD configurations. Namely, AIO.
  38. */
  39. static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd)
  40. {
  41. return ERR_PTR(-ENOSYS);
  42. }
  43. static inline int eventfd_signal(struct eventfd_ctx *ctx, int n)
  44. {
  45. return -ENOSYS;
  46. }
  47. static inline void eventfd_ctx_put(struct eventfd_ctx *ctx)
  48. {
  49. }
  50. static inline int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx,
  51. wait_queue_entry_t *wait, __u64 *cnt)
  52. {
  53. return -ENOSYS;
  54. }
  55. #endif
  56. #endif /* _LINUX_EVENTFD_H */