zephyr/lib
Christopher Friedt 04c9903055 posix: pthread_once: simplify and reduce size of pthread_once_t
Since pthread_once() is both the initializer and executor of
pthread_once_t, it can have maximally two states. Since the
implementation in Zephyr previously aimed to maximize libc
compatibility, we opted to use the definition of pthread_once_t
from newlib, which is a structure with two ints.

It does not make sense to use 64 bits to manage 2 possible
states. The control for that should effectively be a bool.

We maintain compatibility with newlib by asserting (at build
time), that newlib's pthread_once_t is larger than Zephyr's
new struct pthread_once (which just contains a bool).

This allows us to delete the non-standard pthread_key.h
header file (finally).

Reuse the pthread_pool_lock in order to synchronize the related
init function (so that it is only called maximally once from any
thread). The spinlock is only used to test the state and the
init function is not called with the spinlock held.

The alternative was to use an atomic inside of
struct pthread_once. But again, that could be up to 64-bits with
Zephyr's atomics implementation.

Ideally we would use C11 generics or something to support atomics
on 8, 16, 32, and 64-bit primitives.

Lastly, also update declarations for C11 threads as they mostly
mirror our pthread implementation.

This needed to be done as a single commit in order to ensure
continuity of build.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-12-14 09:32:58 +01:00
..
acpi shell: do not enable subsystem/driver shell modules by default 2023-11-20 09:21:40 +01:00
cpp llvm: Add support for LLVM libc++ C++ Standard Library 2023-10-20 14:59:31 +02:00
crc
hash
heap lib: heap: move heap stats to own file 2023-12-13 17:27:54 -05:00
libc posix: pthread_once: simplify and reduce size of pthread_once_t 2023-12-14 09:32:58 +01:00
mem_blocks lib: mem_block: move to own folder 2023-12-13 17:27:54 -05:00
open-amp
os lib: mem_block: move to own folder 2023-12-13 17:27:54 -05:00
posix posix: pthread_once: simplify and reduce size of pthread_once_t 2023-12-14 09:32:58 +01:00
runtime
smf
CMakeLists.txt lib: mem_block: move to own folder 2023-12-13 17:27:54 -05:00
Kconfig lib: mem_block: move to own folder 2023-12-13 17:27:54 -05:00