posix-next API 0.1.0
Out-of-tree Zephyr POSIX module
Loading...
Searching...
No Matches
eventfd.h File Reference

Linux-compatible event notification file descriptor (<sys/eventfd.h>) More...

#include <zephyr/zvfs/eventfd.h>
Include dependency graph for eventfd.h:

Go to the source code of this file.

Macros

#define EFD_SEMAPHORE   ZVFS_EFD_SEMAPHORE
 Semaphore-mode flag: each read decrements the counter by 1 instead of resetting to 0.
 
#define EFD_NONBLOCK   ZVFS_EFD_NONBLOCK
 Non-blocking flag: reads and writes return EAGAIN instead of blocking.
 

Typedefs

typedef zvfs_eventfd_t eventfd_t
 Counter value type for eventfd operations.
 

Functions

int eventfd (unsigned int initval, int flags)
 Create a file descriptor for event notification.
 
int eventfd_read (int fd, eventfd_t *value)
 Read the current counter value from an eventfd.
 
int eventfd_write (int fd, eventfd_t value)
 Add a value to an eventfd counter.
 

Detailed Description

Linux-compatible event notification file descriptor (<sys/eventfd.h>)

eventfd provides a lightweight, kernel-managed counter that can be used for event notification between threads or between a kernel component and user space. It integrates with poll/select/epoll.

Note
eventfd is a Linux extension, not part of POSIX.1-2017, but is widely available on Linux and implemented here for compatibility.

Definition in file eventfd.h.

Macro Definition Documentation

◆ EFD_NONBLOCK

#define EFD_NONBLOCK   ZVFS_EFD_NONBLOCK

Non-blocking flag: reads and writes return EAGAIN instead of blocking.

Definition at line 32 of file eventfd.h.

◆ EFD_SEMAPHORE

#define EFD_SEMAPHORE   ZVFS_EFD_SEMAPHORE

Semaphore-mode flag: each read decrements the counter by 1 instead of resetting to 0.

Definition at line 30 of file eventfd.h.

Typedef Documentation

◆ eventfd_t

typedef zvfs_eventfd_t eventfd_t

Counter value type for eventfd operations.

Definition at line 35 of file eventfd.h.

Function Documentation

◆ eventfd()

int eventfd ( unsigned int  initval,
int  flags 
)

Create a file descriptor for event notification.

The returned file descriptor can be used with POSIX read()/write() or with eventfd_read()/eventfd_write(). It also integrates with poll(), allowing a writing thread to wake a polling thread simply by writing to the eventfd.

When using read()/write(), the buffer size must be exactly 8 bytes or the call will fail with EINVAL.

Parameters
initvalInitial counter value.
flags0, EFD_SEMAPHORE, EFD_NONBLOCK, or their combination.
Returns
New eventfd file descriptor on success, -1 with errno set on failure.
See also
https://man7.org/linux/man-pages/man2/eventfd.2.html

◆ eventfd_read()

int eventfd_read ( int  fd,
eventfd_t value 
)

Read the current counter value from an eventfd.

In normal mode the counter is reset to 0; in EFD_SEMAPHORE mode it is decremented by 1. Blocks if the counter is 0 (unless EFD_NONBLOCK).

Parameters
fdEventfd file descriptor.
valueOutput: counter value read.
Returns
0 on success, -1 with errno set on failure.
See also
https://man7.org/linux/man-pages/man2/eventfd.2.html

◆ eventfd_write()

int eventfd_write ( int  fd,
eventfd_t  value 
)

Add a value to an eventfd counter.

Wakes any thread blocked in eventfd_read(), read(), or poll() on fd.

Parameters
fdEventfd file descriptor.
valueValue to add to the counter.
Returns
0 on success, -1 with errno set on failure.
See also
https://man7.org/linux/man-pages/man2/eventfd.2.html