1 .\" SPDX-License-Identifier: BSD-2-Clause
3 .\" Copyright (c) 2020 Val Packett <val@packett.cool>
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .Nd create a file descriptor for event notification
37 .Fn eventfd "unsigned int initval" "int flags"
39 .Fn eventfd_read "int fd" "eventfd_t *value"
41 .Fn eventfd_write "int fd" "eventfd_t value"
44 creates a special file descriptor with event counter or semaphore semantics,
45 designed for interprocess communication.
46 The returned file descriptor refers to a kernel object containing an
47 unsigned 64-bit integer counter, which is initialized with the value of the
53 argument may contain the result of
57 .Bl -tag -width "EFD_SEMAPHORE" -compact
59 set FD_CLOEXEC on the file descriptor
61 do not block on read/write operations
63 use semaphore semantics
66 File operations have the following semantics:
67 .Bl -tag -width EFD_SEMAPHORE
69 If the counter is zero, the call blocks until the counter becomes non-zero, unless
71 was set, in which case it would fail with
75 If the counter is non-zero:
80 is not set, the current value of the counter is returned,
81 and the value is reset to zero.
85 is set, the constant 1 is returned, and the value is decremented by 1.
88 The numeric value is encoded as 64-bit (8 bytes) in host byte order.
93 if there is less than 8 bytes available in the supplied buffer.
95 Adds the given value to the counter.
96 The maximum value that can be stored in the counter is the
97 maximum unsigned 64-bit integer value minus one (0xfffffffffffffffe).
99 If the resulting value exceeds the maximum, the call would block
100 until the value is reduced by
104 was set, in which case it would fail with
108 The numeric value is encoded as 64-bit (8 bytes) in host byte order.
113 if there is less than 8 bytes available in the supplied buffer,
114 or if the value 0xffffffffffffffff is given.
116 When receiving notifications via
122 the following semantics apply:
125 The file descriptor is readable when the counter is greater than zero.
127 The file descriptor is writable when the counter is less than the maximum value.
131 File descriptors created by
133 are passable to other processes via
135 and are preserved across
137 in both cases the descriptors refer to the same counter from both processes.
141 the created file descriptor will remain open across
153 are thin wrappers around
158 provided for compatibility with glibc.
162 returns a non-negative integer, termed a file descriptor.
163 It returns \-1 on failure, and sets
165 to indicate the error.
171 functions return 0 if the operation succeeded, -1 otherwise.
181 has unknown bits set.
183 The process has already reached its limit for open
186 The system file table is full.
188 No memory was available to create the kernel object.
200 system call is non-standard.
201 It is present in Linux.
205 system call first appeared in