blob: 7094718b653b7b4ce1ebdc4d8ca37734b4284438 [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>
Ulrich Drepperb087498e2008-07-23 21:29:25 -070014
Davide Libenzibcd0b232009-03-31 15:24:18 -070015/*
Martin Sustrik1d730c42013-02-27 17:05:42 -080016 * CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining
Davide Libenzibcd0b232009-03-31 15:24:18 -070017 * 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)
Ulrich Drepperb087498e2008-07-23 21:29:25 -070023#define EFD_CLOEXEC O_CLOEXEC
Ulrich Dreppere7d476d2008-07-23 21:29:38 -070024#define EFD_NONBLOCK O_NONBLOCK
Ulrich Drepperb087498e2008-07-23 21:29:25 -070025
Davide Libenzibcd0b232009-03-31 15:24:18 -070026#define EFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
27#define EFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE)
28
Eric Biggers105f2b72018-01-06 09:45:44 -080029struct eventfd_ctx;
Al Viro4e10f3c2013-08-30 12:29:49 -040030struct file;
31
Davide Libenzi13389012009-06-30 11:41:11 -070032#ifdef CONFIG_EVENTFD
33
Davide Libenzi13389012009-06-30 11:41:11 -070034void eventfd_ctx_put(struct eventfd_ctx *ctx);
Davide Libenzie1ad7462007-05-10 22:23:19 -070035struct file *eventfd_fget(int fd);
Davide Libenzi13389012009-06-30 11:41:11 -070036struct eventfd_ctx *eventfd_ctx_fdget(int fd);
37struct eventfd_ctx *eventfd_ctx_fileget(struct file *file);
Sha Zhengjuee62c6b2012-05-31 16:26:41 -070038__u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n);
Ingo Molnarac6424b2017-06-20 12:06:13 +020039int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t *wait,
Davide Libenzicb289d62010-01-13 09:34:36 -080040 __u64 *cnt);
Davide Libenzie1ad7462007-05-10 22:23:19 -070041
42#else /* CONFIG_EVENTFD */
43
Davide Libenzi13389012009-06-30 11:41:11 -070044/*
45 * Ugly ugly ugly error layer to support modules that uses eventfd but
46 * pretend to work in !CONFIG_EVENTFD configurations. Namely, AIO.
47 */
Davide Libenzi562787a2009-09-22 16:43:57 -070048
Davide Libenzi13389012009-06-30 11:41:11 -070049static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd)
50{
51 return ERR_PTR(-ENOSYS);
52}
Davide Libenzie1ad7462007-05-10 22:23:19 -070053
Davide Libenzi13389012009-06-30 11:41:11 -070054static inline int eventfd_signal(struct eventfd_ctx *ctx, int n)
55{
56 return -ENOSYS;
57}
58
59static inline void eventfd_ctx_put(struct eventfd_ctx *ctx)
60{
61
62}
63
Davide Libenzicb289d62010-01-13 09:34:36 -080064static inline int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx,
Ingo Molnarac6424b2017-06-20 12:06:13 +020065 wait_queue_entry_t *wait, __u64 *cnt)
Davide Libenzicb289d62010-01-13 09:34:36 -080066{
67 return -ENOSYS;
68}
69
Davide Libenzi13389012009-06-30 11:41:11 -070070#endif
Davide Libenzie1ad7462007-05-10 22:23:19 -070071
Davide Libenzie1ad7462007-05-10 22:23:19 -070072#endif /* _LINUX_EVENTFD_H */
73