From b3f341768f45e23efd36d0d7910da0e5af116d7e Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Sat, 1 Aug 2009 17:20:35 +0000 Subject: [PATCH] 2009-08-01 Mike Kestner * glib/GType.cs: lock the types hash to support threaded access and type registration. Apparently gtype access/registration is threadsafe in glib. [Fixes #526229] svn path=/trunk/gtk-sharp/; revision=139247 --- ChangeLog | 6 ++++++ glib/GType.cs | 28 ++++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 07e992523..1db0c5168 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-08-01 Mike Kestner + + * glib/GType.cs: lock the types hash to support threaded access and + type registration. Apparently gtype access/registration is threadsafe + in glib. [Fixes #526229] + 2009-07-30 Mike Kestner * generator/InterfaceGen.cs: remove var keyword usage to fix build on diff --git a/glib/GType.cs b/glib/GType.cs index c3f09404a..027535f44 100755 --- a/glib/GType.cs +++ b/glib/GType.cs @@ -93,10 +93,12 @@ namespace GLib { public static void Register (GType native_type, System.Type type) { - if (native_type != GType.Pointer && native_type != GType.Boxed && native_type != ManagedValue.GType) - types[native_type.Val] = type; - if (type != null) - gtypes[type] = native_type; + lock (types) { + if (native_type != GType.Pointer && native_type != GType.Boxed && native_type != ManagedValue.GType) + types[native_type.Val] = type; + if (type != null) + gtypes[type] = native_type; + } } static GType () @@ -128,8 +130,10 @@ namespace GLib { { GType gtype; - if (gtypes.Contains (type)) - return (GType)gtypes[type]; + lock (types) { + if (gtypes.Contains (type)) + return (GType)gtypes[type]; + } if (type.IsSubclassOf (typeof (GLib.Object))) { gtype = GLib.Object.LookupGType (type); @@ -181,8 +185,10 @@ namespace GLib { public static Type LookupType (IntPtr typeid) { - if (types.Contains (typeid)) - return (Type)types[typeid]; + lock (types) { + if (types.Contains (typeid)) + return (Type)types[typeid]; + } string native_name = Marshaller.Utf8PtrToString (g_type_name (typeid)); @@ -365,8 +371,10 @@ namespace GLib { internal static GType LookupGObjectType (System.Type t) { - if (gtypes.Contains (t)) - return (GType) gtypes [t]; + lock (types) { + if (gtypes.Contains (t)) + return (GType) gtypes [t]; + } PropertyInfo pi = t.GetProperty ("GType", BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public); if (pi != null)