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