zephyr/lib
Christopher Friedt e6eb0a705b posix: eventfd: revise locking, signaling, and allocation
TL;DR - a complete rewrite.

Previously, the prototypical `eventfd()` usage (one thread
performing a blocking `read()`, followed by another thread
performing a `write()`) would deadlock Zephyr. This shortcoming
has existed in Zephyr's `eventfd()` implementation from the
start and the suggested workaround was to use `poll()`.

However, that is not sufficient for integrating 3rd-party
libraries that may rely on proper `eventfd()` blocking
operations such as `eventfd_read()` and `eventfd_write()`.

The culprit was the per-fdtable-entry `struct k_mutex`.

Here we perform a minor revision of the locking strategy
and employ `k_condvar_broadcast()` and `k_condvar_wait()`
to signal and wait on the holder of a given `struct k_mutex`.

It is important to note, however, that the primary means of
synchronizing the eventfd state is actually the eventfd
spinlock. The fdtable mutex and condition variable are mainly
used for the purposes of blocking io (r,w,close) and are not
used in the code path of non-blocking reads.

The `wait_q` and `k_poll_signal` entries were removed from
`struct eventfd` as they were unnecessary.

Additionally, switch to using a bitarray because it is
possibly faster than linear search for allocating and
deallocating eventfd resources.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-06-02 18:45:46 -04:00
..
cpp lib/cpp: Remove CONFIG_CPP_MAIN 2023-05-31 06:16:35 -04:00
hash lib: hashmap: Move hash table files lib/hashmap 2023-03-02 12:03:07 -05:00
libc libc: minimal: Add 'break' to suppress fall-through error in atoi.c 2023-05-31 14:41:25 -04:00
open-amp open-amp: Fix compilation with cache enabled 2023-04-18 12:12:56 +02:00
os lib: os: add k_condvar for each fdtable entry 2023-06-02 18:45:46 -04:00
posix posix: eventfd: revise locking, signaling, and allocation 2023-06-02 18:45:46 -04:00
smf lib: smf: fix include 2022-05-25 11:14:18 +09:00
CMakeLists.txt lib: posix: move fnmatch from lib/util to lib/posix 2023-03-03 17:40:14 +09:00
Kconfig lib: posix: move fnmatch from lib/util to lib/posix 2023-03-03 17:40:14 +09:00