zephyr/lib/posix
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
..
getopt
CMakeLists.txt
Kconfig
Kconfig.barrier
Kconfig.clock
Kconfig.cond
Kconfig.eventfd
Kconfig.fnmatch
Kconfig.fs
Kconfig.getopt
Kconfig.key
Kconfig.limits
Kconfig.mqueue
Kconfig.mutex
Kconfig.pthread
Kconfig.semaphore
Kconfig.signal posix: pthread: implement pthread_sigmask() 2023-12-04 20:49:35 -05:00
Kconfig.spinlock
Kconfig.template.pooled_ipc_type
Kconfig.template.pooled_type
Kconfig.template.with_logging
Kconfig.template.with_url
Kconfig.timer
Kconfig.uname
_common.c
barrier.c
clock.c
cond.c
eventfd.c
fnmatch.c
fs.c
key.c posix: pthread_once: simplify and reduce size of pthread_once_t 2023-12-14 09:32:58 +01:00
mqueue.c
mutex.c
nanosleep.c
perror.c
posix_internal.h posix: pthread: implement pthread_sigmask() 2023-12-04 20:49:35 -05:00
pthread.c posix: pthread_once: simplify and reduce size of pthread_once_t 2023-12-14 09:32:58 +01:00
pthread_sched.h
rwlock.c
sched.c
semaphore.c
signal.c
sleep.c
spinlock.c
timer.c
uname.c