summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-11-02 10:35:25 +0100
committerThomas Haller <thaller@redhat.com>2021-06-10 21:29:33 +0200
commit3e1255fbfbc5951e415c78336bdd0cc34a0f5c84 (patch)
treeb296c48c916be77fdf96f5b9fe8a70e65b0e996d
parent3bf455a53186c59037511258282c0136ab6c5fdd (diff)
downloadNetworkManager-3e1255fbfbc5951e415c78336bdd0cc34a0f5c84.tar.gz
shared: also reimplement g_atomic_pointer_set() macro
It's not strictly necessary, because contrary to g_atomic_pointer_get() and g_atomic_pointer_compare_and_exchange(), glib's variant for the setter is mostly fine. Still, reimplement it, because we use typeof() eagerly and can thus add more static checks than glib. (cherry picked from commit 7c60e984b6fe742f5719550bd7ccad64608ecb6e) (cherry picked from commit 6ded463f36d945658d601970b5089f2f887f4c5b) (cherry picked from commit 976b358be688864716ade41b94b5872ad95ff4f7) (cherry picked from commit 296a770a8588b2437872fcc23e878a50a3f6e8d1) (cherry picked from commit 32c81a29d5f378fe0682db99c1df31bfbba34054) (cherry picked from commit 4862953355a67da13c4601f4e92101922fa71c3f)
-rw-r--r--shared/nm-glib-aux/nm-glib.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-glib.h b/shared/nm-glib-aux/nm-glib.h
index 9ae8d9002b..22f4d8b510 100644
--- a/shared/nm-glib-aux/nm-glib.h
+++ b/shared/nm-glib-aux/nm-glib.h
@@ -602,6 +602,25 @@ _g_atomic_pointer_get (void **atomic)
(typeof (*_atomic)) _g_atomic_pointer_get ((void **) _atomic); \
})
+/* Reimplement g_atomic_pointer_set() macro too. Our variant does more type
+ * checks. */
+static inline void
+_g_atomic_pointer_set (void **atomic, void *newval)
+{
+ return g_atomic_pointer_set (atomic, newval);
+}
+#undef g_atomic_pointer_set
+#define g_atomic_pointer_set(atomic, newval) \
+ ({ \
+ typeof (*atomic) *const _atomic = (atomic); \
+ typeof (*_atomic) const _newval = (newval); \
+ _nm_unused gconstpointer const _val_type_check = _newval; \
+ \
+ (void) (0 ? (gpointer) * (_atomic) : NULL); \
+ \
+ _g_atomic_pointer_set ((void **) _atomic, (void *) _newval); \
+ })
+
/* Glib implements g_atomic_pointer_compare_and_exchange() as a macro.
* For one, to inline the atomic operation and also to perform some type checks
* on the arguments.