zephyr/lib/posix
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
..
getopt iterable_sections: move to specific header 2023-05-22 10:42:30 +02:00
clock.c posix: clock: fix seconds calculation 2023-01-04 21:12:58 +01:00
CMakeLists.txt lib: posix: move fnmatch from lib/util to lib/posix 2023-03-03 17:40:14 +09:00
eventfd.c posix: eventfd: revise locking, signaling, and allocation 2023-06-02 18:45:46 -04:00
fnmatch.c posix: fnmatch: correct (many) compliance issues 2023-03-03 17:40:14 +09:00
fs.c posix: fs: avoid adding open() alias with newlib and picolibc 2023-01-23 09:57:31 -08:00
Kconfig posix: eventfd: depends on polling 2023-05-09 23:32:57 +09:00
mqueue.c posix: mqueue: do not typedef mq_attr 2023-01-23 09:57:31 -08:00
nanosleep.c sys: util: migrate all files to DIV_ROUND_UP 2023-04-11 12:00:37 +02:00
perror.c lib: posix: add perror() implementation 2022-07-04 22:53:36 +02:00
posix_internal.h posix: sched: add support for SCHED_OTHER 2023-04-29 13:14:40 -07:00
pthread.c posix: sched: add support for SCHED_OTHER 2023-04-29 13:14:40 -07:00
pthread_barrier.c lib: migrate includes to <zephyr/...> 2022-05-06 19:58:09 +02:00
pthread_common.c lib: migrate includes to <zephyr/...> 2022-05-06 19:58:09 +02:00
pthread_cond.c posix: cond: abstract pthread_cond_t as uint32_t 2022-11-19 14:16:38 +09:00
pthread_key.c posix: key: abstract pthread_key_t as uint32_t 2022-11-24 04:19:01 +09:00
pthread_mutex.c posix: headers: harmonize remaining types with newlib 2023-01-10 09:02:21 +09:00
pthread_rwlock.c lib: migrate includes to <zephyr/...> 2022-05-06 19:58:09 +02:00
pthread_sched.c posix: sched: add support for SCHED_OTHER 2023-04-29 13:14:40 -07:00
pthread_sched.h posix: sched: add support for SCHED_OTHER 2023-04-29 13:14:40 -07:00
semaphore.c lib: posix: semaphore: use consistent timebase in sem_timedwait 2022-06-24 20:12:05 +02:00
sleep.c lib: posix: update usleep() to follow the POSIX spec 2022-11-24 19:31:33 -05:00
timer.c posix: Kconfig for timer_create wait time 2022-12-27 15:34:13 +01:00