1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-10-28 23:34:53 +03:00

Add once_flag, ONCE_FLAG_INIT and call_once to stdlib.h for C23

C23 adds once_flag, ONCE_FLAG_INIT and call_once to stdlib.h (in C11
they were only in threads.h, in C23 they are in both headers; this
change came from N2840).  Implement this change, with a
bits/types/once_flag.h header for the common type and initializer
definitions.

Note that there's an omnibus bug (bug 33001) that covers more than
just these missing definitions.

This doesn't seem a significant enough feature to be worth mentioning
in NEWS.

ISO C is not concerned with whether functions are in libc or
libpthread, but POSIX links this to what header they are declared in,
so functions declared in stdlib.h are supposed to be in libc.
However, the current edition of POSIX is based on C17; hopefully Hurd
glibc will have completed the merge of libpthread into libc (in
particular, moving call_once) well before a future edition of POSIX
based on C23 (or a later version of ISO C) is released.

Tested for x86_64 and x86.
This commit is contained in:
Joseph Myers
2025-10-01 15:15:15 +00:00
parent 0f201f4a81
commit a7ddbf456d
5 changed files with 40 additions and 3 deletions

View File

@@ -1158,6 +1158,14 @@ extern int getloadavg (double __loadavg[], int __nelem)
extern int ttyslot (void) __THROW;
#endif
#if __GLIBC_USE (ISOC23)
# include <bits/types/once_flag.h>
/* Call function __FUNC exactly once, even if invoked from several threads.
All calls must be made with the same __FLAGS object. */
extern void call_once (once_flag *__flag, void (*__func)(void));
#endif
#include <bits/stdlib-float.h>
/* Define some macros helping to catch buffer overflows. */