[PATCH spice-gtk 06/25] glib-compat: add g_clear_pointer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A helpful macro from glib 2.34
---
 gtk/glib-compat.h |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/gtk/glib-compat.h b/gtk/glib-compat.h
index bd8f3de..aa750b2 100644
--- a/gtk/glib-compat.h
+++ b/gtk/glib-compat.h
@@ -106,4 +106,24 @@ GType spice_main_context_get_type (void) G_GNUC_CONST;
 # define G_SIGNAL_DEPRECATED (1 << 9)
 #endif
 
+#ifndef g_clear_pointer
+#define g_clear_pointer(pp, destroy) \
+  G_STMT_START {                                                               \
+    G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer));                       \
+    /* Only one access, please */                                              \
+    gpointer *_pp = (gpointer *) (pp);                                         \
+    gpointer _p;                                                               \
+    /* This assignment is needed to avoid a gcc warning */                     \
+    GDestroyNotify _destroy = (GDestroyNotify) (destroy);                      \
+                                                                               \
+    (void) (0 ? (gpointer) *(pp) : 0);                                         \
+    do                                                                         \
+      _p = g_atomic_pointer_get (_pp);                                         \
+    while G_UNLIKELY (!g_atomic_pointer_compare_and_exchange (_pp, _p, NULL)); \
+                                                                               \
+    if (_p)                                                                    \
+      _destroy (_p);                                                           \
+  } G_STMT_END
+#endif
+
 #endif /* GLIB_COMPAT_H */
-- 
1.7.10.4

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]