EVENTFD(3C) | Standard C Library Functions | EVENTFD(3C) |
eventfd
,
eventfd_read
, eventfd_write
— create a file descriptor for event
notification
#include
<sys/eventfd.h>
int
eventfd
(unsigned int initval,
int flags);
int
eventfd_read
(int fd,
eventfd_t *valp);
int
eventfd_write
(int fd,
eventfd_t val);
The
eventfd
()
function creates an eventfd(7)
instance that has an associated 64-bit unsigned counter. It returns a file
descriptor that can be operated upon via
read(2),
write(2) and the facilities that notify
of file descriptor activity (e.g.,
poll(2),
port_get(3C),
epoll_wait(3C)). To dispose of
the instance, close(2) should be called
on the file descriptor.
The initval argument specifies the initial value of the 64-bit counter associated with the instance. (Note that this limits the initial value to be a 32-bit quantity despite the fact that the underlying counter is 64-bit).
The flags argument specifies additional parameters for the instance, and can have any of the following values:
EFD_CLOEXEC
O_CLOEXEC
.EFD_NONBLOCK
eventfd
instance that has been initialized with
EFD_NONBLOCK
will return
EAGAIN
in lieu of blocking if the count associated
with the instance is zero.EFD_SEMAPHORE
The following operations can be performed upon an
eventfd
instance:
EFD_SEMAPHORE
with respect to the instance: if
EFD_SEMAPHORE
was set when the instance was
created, read(2) will
atomically decrement the counter if (and when) it is
non-zero, copying the value 1 to the eight byte buffer passed to the
system call; if EFD_SEMAPHORE
was not set,
read(2) will atomically
clear the counter if (and when) it is non-zero, copying the former
value of the counter to the eight byte buffer passed to the system call.
In either case, read(2) will block if
the counter is zero (or return EAGAIN
if the
instance was created with EFD_NONBLOCK
). If the
buffer specified to read(2) is less
than eight bytes in length, EINVAL
will be
returned.EAGAIN
if the instance was created with
EFD_NONBLOCK
). If the buffer specified to
write(2) is less than eight bytes in
length, EINVAL
will be returned.POLLIN
and POLLRDNORM
will be set; if the value 1 can be
added the value without blocking, POLLOUT
and
POLLWRNORM
will be set.eventfd_read
()
and
eventfd_write
()
are provided for compatibility with
glibc
and are wrappers around read(2) and
write(2), respectively. They return
0 if the correct number of bytes was transferred and
-1 otherwise. These functions may return
-1 without setting errno.
Upon successful completion, eventfd
()
returns a file descriptor associated with the instance. Otherwise,
-1 is returned and errno is set to
indicate the error.
Upon successful completion, eventfd_read
()
and eventfd_write
() return 0.
Otherwise, -1 is returned.
The eventfd
() function will fail if:
poll(2), read(2), write(2), epoll_wait(3C), port_get(3C), eventfd(7)
August 10, 2021 | OmniOS |