[glib] Fix thread-safety



commit ec79146572aece95c7bc032b486e6a57015ee6e4
Author: Benjamin Otte <otte gnome org>
Date:   Fri Nov 20 16:47:09 2009 +0100

    Fix thread-safety
    
    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 |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/gobject/gtype.c b/gobject/gtype.c
index d582242..d2bca55 100644
--- a/gobject/gtype.c
+++ b/gobject/gtype.c
@@ -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;



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