Fix thread-safety
authorBenjamin Otte <otte@gnome.org>
Fri, 20 Nov 2009 15:47:09 +0000 (16:47 +0100)
committerBenjamin Otte <otte@gnome.org>
Fri, 20 Nov 2009 15:49:47 +0000 (16:49 +0100)
The n_children variable can be written when locked, while the n_supers
variable is read at any time. As they both share the same bytes,
accessing them is not threadsafe.
This patch puts them into different bytes.

Thanks to Xan Lopez and valgrind for noticing this.

gobject/gtype.c

index d5822422e235ca6c076a0a3b54d59e671a3c2e89..d2bca5535f07119261bb8d4d34dbd8efb25e87bb 100644 (file)
@@ -223,13 +223,13 @@ typedef enum
 struct _TypeNode
 {
   GTypePlugin *plugin;
-  guint        n_children : 12;
+  guint        n_children; /* writable with lock */
   guint        n_supers : 8;
   guint        _prot_n_ifaces_prerequisites : 9;
   guint        is_classed : 1;
   guint        is_instantiatable : 1;
   guint        mutatable_check_cache : 1;      /* combines some common path checks */
-  GType       *children;
+  GType       *children; /* writable with lock */
   TypeData * volatile data;
   GQuark       qname;
   GData       *global_gdata;