![]() |
posix-next API 0.1.0
Out-of-tree Zephyr POSIX module
|
Linux-compatible event notification file descriptor (<sys/eventfd.h>) More...
#include <zephyr/zvfs/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. | |
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.
Definition in file eventfd.h.
| #define EFD_NONBLOCK ZVFS_EFD_NONBLOCK |
| #define EFD_SEMAPHORE ZVFS_EFD_SEMAPHORE |
| typedef zvfs_eventfd_t eventfd_t |
| 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.
| initval | Initial counter value. |
| flags | 0, EFD_SEMAPHORE, EFD_NONBLOCK, or their combination. |
| 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).
| fd | Eventfd file descriptor. |
| value | Output: counter value read. |
| 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.
| fd | Eventfd file descriptor. |
| value | Value to add to the counter. |