Remove more _Atomic keywords from public headers

It's been thirteen years and C++ still hasn't implemented this wonderful
simple builtin keyword. In C++23 a solution was provided for making this
work in C++ which is libcxx's stdatomic.h. Including that header schleps
in literally 253 unique header files!! Many of the header files it needs
are libc header files like pthread.h where we need to have the _Atomic()
keyword, but since <atomic> depends on pthreads we can't have it include
the <stdatomic.h> header that defines _Atomic for C++ users, and instead
we simply make the type non-atomic, hoping and praying only C code shall
use those internal data structures. This just shows how STL clowns can't
be trusted to define the innermost primitives of a language. They should
instead be focusing on being the best at algorithms and data structures.
This commit is contained in:
Justine Tunney 2024-07-24 13:34:15 -07:00
parent 4a1ae86124
commit 7ba9a73840
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
4 changed files with 4 additions and 49 deletions

View file

@ -27,7 +27,7 @@ enum {
typedef uintptr_t thrd_t; typedef uintptr_t thrd_t;
typedef void (*tss_dtor_t)(void *); typedef void (*tss_dtor_t)(void *);
typedef int (*thrd_start_t)(void *); typedef int (*thrd_start_t)(void *);
typedef _Atomic(uint32_t) once_flag; typedef uint32_t once_flag;
void call_once(once_flag *, void (*)(void)); void call_once(once_flag *, void (*)(void));
int thrd_create(thrd_t *, thrd_start_t, void *); int thrd_create(thrd_t *, thrd_start_t, void *);

View file

@ -1,46 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_TYPE2STR_H_
#define COSMOPOLITAN_LIBC_TYPE2STR_H_
#if __STDC_VERSION__ + 0 >= 201112
/* clang-format off */
#define _TYPE2STR(X) \
_Generic(X, \
_Bool: "_Bool", \
signed char: "signed char", \
unsigned char: "unsigned char", \
char: "char", \
short: "short", \
unsigned short: "unsigned short", \
int: "int", \
unsigned: "unsigned", \
long: "long", \
unsigned long: "unsigned long", \
long long: "long long", \
unsigned long long: "unsigned long long", \
__int128: "__int128", \
unsigned __int128: "unsigned __int128", \
float: "float", \
double: "double", \
long double: "long double")
#define _PRINTF_GENERIC(X, D, U) \
_Generic(X, \
_Bool: "hhh" U, \
signed char: "hh" D, \
unsigned char: "hh" U, \
char: "hh" D, \
short: "h" D, \
unsigned short: "h" U, \
int: D, \
unsigned: U, \
long: "l" D, \
unsigned long: "l" U, \
long long: "ll" D, \
unsigned long long: "ll" U, \
float: "f", \
double: "f", \
long double: "Lf")
/* clang-format on */
#endif /* C11 */
#endif /* COSMOPOLITAN_LIBC_TYPE2STR_H_ */

View file

@ -81,7 +81,7 @@ char *utf32to8(const wchar_t *, size_t, size_t *) __wur;
char *xhomedir(void) __wur; char *xhomedir(void) __wur;
char *xstripext(const char *) __wur; char *xstripext(const char *) __wur;
char *xstripexts(const char *) __wur; char *xstripexts(const char *) __wur;
void *xload(_Atomic(void *) *, const void *, size_t, size_t); void *xload(void *, const void *, size_t, size_t);
int rmrf(const char *); int rmrf(const char *);
char *xbasename(const char *) paramsnonnull() char *xbasename(const char *) paramsnonnull()
returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull; returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;

View file

@ -40,7 +40,8 @@
* @param m is byte length of inflated data * @param m is byte length of inflated data
* @return pointer to inflated data * @return pointer to inflated data
*/ */
void *xload(_Atomic(void *) *a, const void *p, size_t n, size_t m) { void *xload(void *a_, const void *p, size_t n, size_t m) {
_Atomic(void *) *a = (_Atomic(void *) *)a_;
void *r, *z; void *r, *z;
if ((r = atomic_load_explicit(a, memory_order_acquire))) if ((r = atomic_load_explicit(a, memory_order_acquire)))
return r; return r;