summaryrefslogtreecommitdiff
path: root/src/glibext/objhole.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/glibext/objhole.h')
-rw-r--r--src/glibext/objhole.h75
1 files changed, 62 insertions, 13 deletions
diff --git a/src/glibext/objhole.h b/src/glibext/objhole.h
index cf9fc28..38f4bd5 100644
--- a/src/glibext/objhole.h
+++ b/src/glibext/objhole.h
@@ -25,6 +25,7 @@
#define _GLIBEXT_OBJHOLE_H
+#include <glib.h>
#include <glib-object.h>
@@ -42,22 +43,33 @@
* GData *qdata;
* };
*
- * L'espace entre les deux derniers champs est exploité ici.
+ * En revanche, le fichier "glib/gobject/gobject.c" précise la définition
+ * réelle de la structure selon l'environnement :
+ *
+ * #if SIZEOF_INT == 4 && GLIB_SIZEOF_VOID_P == 8
+ * #define HAVE_OPTIONAL_FLAGS
+ * #endif
+ *
+ * typedef struct
+ * {
+ * GTypeInstance g_type_instance;
+ * guint ref_count;
+ * #ifdef HAVE_OPTIONAL_FLAGS
+ * guint optional_flags;
+ * #endif
+ * GData *qdata;
+ * } GObjectReal;
+ *
+ * G_STATIC_ASSERT(sizeof(GObject) == sizeof(GObjectReal));
+ * G_STATIC_ASSERT(G_STRUCT_OFFSET(GObject, ref_count) == G_STRUCT_OFFSET(GObjectReal, ref_count));
+ * G_STATIC_ASSERT(G_STRUCT_OFFSET(GObject, qdata) == G_STRUCT_OFFSET(GObjectReal, qdata));
+ *
+ * L'espace entre les deux derniers champs ne peut donc être pleinement exploité deux fois.
*/
+#if 0
-#define INIT_GOBJECT_EXTRA(obj) \
- do \
- { \
- guint *___space; \
- ___space = (((guint *)&obj->ref_count) + 1); \
- BUILD_BUG_ON((___space + 1) == (guint *)&obj->qdata); \
- *___space = 0; \
- } \
- while (0)
-
-
-#define GET_GOBJECT_EXTRA(obj, tp) \
+# define GET_GOBJECT_EXTRA(obj, tp) \
({ \
BUILD_BUG_ON(sizeof(tp) > sizeof(guint)); \
tp *___result; \
@@ -66,6 +78,7 @@
___result; \
})
+#endif
/**
@@ -90,5 +103,41 @@
#endif
+/* Verrou d'accès pour une encapsulation */
+typedef struct _lockable_obj_extra_t
+{
+ gint lock; /* Gestion d'accès aux fanions */
+
+} lockable_obj_extra_t;
+
+
+#define INIT_GOBJECT_EXTRA_LOCK(xtr) \
+ do \
+ { \
+ lockable_obj_extra_t *__lockable; \
+ __lockable = (lockable_obj_extra_t *)xtr; \
+ __lockable->lock = 0; \
+ } \
+ while (0)
+
+#define LOCK_GOBJECT_EXTRA(xtr) \
+ do \
+ { \
+ lockable_obj_extra_t *__lockable; \
+ __lockable = (lockable_obj_extra_t *)xtr; \
+ g_bit_lock(&__lockable->lock, HOLE_LOCK_BIT); \
+ } \
+ while (0)
+
+#define UNLOCK_GOBJECT_EXTRA(xtr) \
+ do \
+ { \
+ lockable_obj_extra_t *__lockable; \
+ __lockable = (lockable_obj_extra_t *)xtr; \
+ g_bit_unlock(&__lockable->lock, HOLE_LOCK_BIT); \
+ } \
+ while (0)
+
+
#endif /* _GLIBEXT_OBJHOLE_H */