blob: ffcc7724ca210097f70cca236d8e249d09541e64 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Davide Libenzie1ad7462007-05-10 22:23:19 -07002/*
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
Ulrich Drepperb087498e2008-07-23 21:29:25 -070012#include <linux/fcntl.h>
Davide Libenzicb289d62010-01-13 09:34:36 -080013#include <linux/wait.h>
Arnd Bergmannfa3fc2a2018-07-26 16:37:38 -070014#include <linux/err.h>
Ulrich Drepperb087498e2008-07-23 21:29:25 -070015
Davide Libenzibcd0b232009-03-31 15:24:18 -070016/*
Martin Sustrik1d730c42013-02-27 17:05:42 -080017 * CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining
Davide Libenzibcd0b232009-03-31 15:24:18 -070018 * 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)
Ulrich Drepperb087498e2008-07-23 21:29:25 -070024#define EFD_CLOEXEC O_CLOEXEC
Ulrich Dreppere7d476d2008-07-23 21:29:38 -070025#define EFD_NONBLOCK O_NONBLOCK
Ulrich Drepperb087498e2008-07-23 21:29:25 -070026
Davide Libenzibcd0b232009-03-31 15:24:18 -070027#define EFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
28#define EFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE)
29
Eric Biggers105f2b72018-01-06 09:45:44 -080030struct eventfd_ctx;
Al Viro4e10f3c2013-08-30 12:29:49 -040031struct file;
32
Davide Libenzi13389012009-06-30 11:41:11 -070033#ifdef CONFIG_EVENTFD
34
Davide Libenzi13389012009-06-30 11:41:11 -070035void eventfd_ctx_put(struct eventfd_ctx *ctx);
Davide Libenzie1ad7462007-05-10 22:23:19 -070036struct file *eventfd_fget(int fd);
Davide Libenzi13389012009-06-30 11:41:11 -070037struct eventfd_ctx *eventfd_ctx_fdget(int fd);
38struct eventfd_ctx *eventfd_ctx_fileget(struct file *file);
Sha Zhengjuee62c6b2012-05-31 16:26:41 -070039__u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n);
Ingo Molnarac6424b2017-06-20 12:06:13 +020040int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t *wait,
Davide Libenzicb289d62010-01-13 09:34:36 -080041 __u64 *cnt);
Davide Libenzie1ad7462007-05-10 22:23:19 -070042
43#else /* CONFIG_EVENTFD */
44
Davide Libenzi13389012009-06-30 11:41:11 -070045/*
46 * Ugly ugly ugly error layer to support modules that uses eventfd but
47 * pretend to work in !CONFIG_EVENTFD configurations. Namely, AIO.
48 */
Davide Libenzi562787a2009-09-22 16:43:57 -070049
Davide Libenzi13389012009-06-30 11:41:11 -070050static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd)
51{
52 return ERR_PTR(-ENOSYS);
53}
Davide Libenzie1ad7462007-05-10 22:23:19 -070054
Davide Libenzi13389012009-06-30 11:41:11 -070055static inline int eventfd_signal(struct eventfd_ctx *ctx, int n)
56{
57 return -ENOSYS;
58}
59
60static inline void eventfd_ctx_put(struct eventfd_ctx *ctx)
61{
62
63}
64
Davide Libenzicb289d62010-01-13 09:34:36 -080065static inline int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx,
Ingo Molnarac6424b2017-06-20 12:06:13 +020066 wait_queue_entry_t *wait, __u64 *cnt)
Davide Libenzicb289d62010-01-13 09:34:36 -080067{
68 return -ENOSYS;
69}
70
Davide Libenzi13389012009-06-30 11:41:11 -070071#endif
Davide Libenzie1ad7462007-05-10 22:23:19 -070072
Davide Libenzie1ad7462007-05-10 22:23:19 -070073#endif /* _LINUX_EVENTFD_H */
74