blob: dc4fd8a6644dd62da4837ebc7e9d20a24716e59a [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>
Jens Axboeb5e683d2020-02-02 08:23:03 -070015#include <linux/percpu-defs.h>
16#include <linux/percpu.h>
Ulrich Drepperb087498e2008-07-23 21:29:25 -070017
Davide Libenzibcd0b232009-03-31 15:24:18 -070018/*
Martin Sustrik1d730c42013-02-27 17:05:42 -080019 * CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining
Davide Libenzibcd0b232009-03-31 15:24:18 -070020 * 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)
Ulrich Drepperb087498e2008-07-23 21:29:25 -070026#define EFD_CLOEXEC O_CLOEXEC
Ulrich Dreppere7d476d2008-07-23 21:29:38 -070027#define EFD_NONBLOCK O_NONBLOCK
Ulrich Drepperb087498e2008-07-23 21:29:25 -070028
Davide Libenzibcd0b232009-03-31 15:24:18 -070029#define EFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
30#define EFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE)
31
Eric Biggers105f2b72018-01-06 09:45:44 -080032struct eventfd_ctx;
Al Viro4e10f3c2013-08-30 12:29:49 -040033struct file;
34
Davide Libenzi13389012009-06-30 11:41:11 -070035#ifdef CONFIG_EVENTFD
36
Davide Libenzi13389012009-06-30 11:41:11 -070037void eventfd_ctx_put(struct eventfd_ctx *ctx);
Davide Libenzie1ad7462007-05-10 22:23:19 -070038struct file *eventfd_fget(int fd);
Davide Libenzi13389012009-06-30 11:41:11 -070039struct eventfd_ctx *eventfd_ctx_fdget(int fd);
40struct eventfd_ctx *eventfd_ctx_fileget(struct file *file);
Sha Zhengjuee62c6b2012-05-31 16:26:41 -070041__u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n);
Ingo Molnarac6424b2017-06-20 12:06:13 +020042int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t *wait,
Davide Libenzicb289d62010-01-13 09:34:36 -080043 __u64 *cnt);
Davide Libenzie1ad7462007-05-10 22:23:19 -070044
Jens Axboeb5e683d2020-02-02 08:23:03 -070045DECLARE_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
Davide Libenzie1ad7462007-05-10 22:23:19 -070052#else /* CONFIG_EVENTFD */
53
Davide Libenzi13389012009-06-30 11:41:11 -070054/*
55 * Ugly ugly ugly error layer to support modules that uses eventfd but
56 * pretend to work in !CONFIG_EVENTFD configurations. Namely, AIO.
57 */
Davide Libenzi562787a2009-09-22 16:43:57 -070058
Davide Libenzi13389012009-06-30 11:41:11 -070059static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd)
60{
61 return ERR_PTR(-ENOSYS);
62}
Davide Libenzie1ad7462007-05-10 22:23:19 -070063
Davide Libenzi13389012009-06-30 11:41:11 -070064static 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
Davide Libenzicb289d62010-01-13 09:34:36 -080074static inline int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx,
Ingo Molnarac6424b2017-06-20 12:06:13 +020075 wait_queue_entry_t *wait, __u64 *cnt)
Davide Libenzicb289d62010-01-13 09:34:36 -080076{
77 return -ENOSYS;
78}
79
Jens Axboeb5e683d2020-02-02 08:23:03 -070080static inline bool eventfd_signal_count(void)
81{
82 return false;
83}
84
Davide Libenzi13389012009-06-30 11:41:11 -070085#endif
Davide Libenzie1ad7462007-05-10 22:23:19 -070086
Davide Libenzie1ad7462007-05-10 22:23:19 -070087#endif /* _LINUX_EVENTFD_H */
88