Add proper atomic types
Instead of using int
and void*
and then having to remember to add a comment to a declaration, like:
int foo = 0; /* atomic */
or
struct Foo {
char *name;
int value; /* atomic */
};
to signal the fact that we're using something atomically, we should crib one out from the Linux kernel, and introduce type aliases:
typedef int gatomic;
typedef gpointer gatomicptr;
Or, even better:
#if G_C_STD_CHECK_VERSION(11) && !defined(__STDC_NO_ATOMICS__)
#include <stdatomic.h>
typedef _Atomic int gatomic;
typedef _Atomic gpointer gatomicptr;
#else
typedef int gatomic;
typedef gpointer gatomicptr;
#endif
Ideally, this would also allow us to replace the type of the arguments in the g_atomic_*
functions, so it's trivial to see what's what.