Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *  include/linux/eventfd.h
0004  *
0005  *  Copyright (C) 2007  Davide Libenzi <davidel@xmailserver.org>
0006  *
0007  */
0008 
0009 #ifndef _LINUX_EVENTFD_H
0010 #define _LINUX_EVENTFD_H
0011 
0012 #include <linux/fcntl.h>
0013 #include <linux/wait.h>
0014 #include <linux/err.h>
0015 #include <linux/percpu-defs.h>
0016 #include <linux/percpu.h>
0017 #include <linux/sched.h>
0018 
0019 /*
0020  * CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining
0021  * new flags, since they might collide with O_* ones. We want
0022  * to re-use O_* flags that couldn't possibly have a meaning
0023  * from eventfd, in order to leave a free define-space for
0024  * shared O_* flags.
0025  */
0026 #define EFD_SEMAPHORE (1 << 0)
0027 #define EFD_CLOEXEC O_CLOEXEC
0028 #define EFD_NONBLOCK O_NONBLOCK
0029 
0030 #define EFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
0031 #define EFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE)
0032 
0033 struct eventfd_ctx;
0034 struct file;
0035 
0036 #ifdef CONFIG_EVENTFD
0037 
0038 void eventfd_ctx_put(struct eventfd_ctx *ctx);
0039 struct file *eventfd_fget(int fd);
0040 struct eventfd_ctx *eventfd_ctx_fdget(int fd);
0041 struct eventfd_ctx *eventfd_ctx_fileget(struct file *file);
0042 __u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n);
0043 int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t *wait,
0044                   __u64 *cnt);
0045 void eventfd_ctx_do_read(struct eventfd_ctx *ctx, __u64 *cnt);
0046 
0047 static inline bool eventfd_signal_allowed(void)
0048 {
0049     return !current->in_eventfd_signal;
0050 }
0051 
0052 #else /* CONFIG_EVENTFD */
0053 
0054 /*
0055  * Ugly ugly ugly error layer to support modules that uses eventfd but
0056  * pretend to work in !CONFIG_EVENTFD configurations. Namely, AIO.
0057  */
0058 
0059 static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd)
0060 {
0061     return ERR_PTR(-ENOSYS);
0062 }
0063 
0064 static inline int eventfd_signal(struct eventfd_ctx *ctx, int n)
0065 {
0066     return -ENOSYS;
0067 }
0068 
0069 static inline void eventfd_ctx_put(struct eventfd_ctx *ctx)
0070 {
0071 
0072 }
0073 
0074 static inline int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx,
0075                         wait_queue_entry_t *wait, __u64 *cnt)
0076 {
0077     return -ENOSYS;
0078 }
0079 
0080 static inline bool eventfd_signal_allowed(void)
0081 {
0082     return true;
0083 }
0084 
0085 static inline void eventfd_ctx_do_read(struct eventfd_ctx *ctx, __u64 *cnt)
0086 {
0087 
0088 }
0089 
0090 #endif
0091 
0092 #endif /* _LINUX_EVENTFD_H */
0093