2009-08-01 Mike Kestner <mkestner@novell.com>

* 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
This commit is contained in:
Mike Kestner 2009-08-01 17:20:35 +00:00
parent b122c1b11d
commit b3f341768f
2 changed files with 24 additions and 10 deletions

View File

@ -1,3 +1,9 @@
2009-08-01 Mike Kestner <mkestner@novell.com>
* 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 <mkestner@novell.com> 2009-07-30 Mike Kestner <mkestner@novell.com>
* generator/InterfaceGen.cs: remove var keyword usage to fix build on * generator/InterfaceGen.cs: remove var keyword usage to fix build on

View File

@ -93,10 +93,12 @@ namespace GLib {
public static void Register (GType native_type, System.Type type) public static void Register (GType native_type, System.Type type)
{ {
if (native_type != GType.Pointer && native_type != GType.Boxed && native_type != ManagedValue.GType) lock (types) {
types[native_type.Val] = type; if (native_type != GType.Pointer && native_type != GType.Boxed && native_type != ManagedValue.GType)
if (type != null) types[native_type.Val] = type;
gtypes[type] = native_type; if (type != null)
gtypes[type] = native_type;
}
} }
static GType () static GType ()
@ -128,8 +130,10 @@ namespace GLib {
{ {
GType gtype; GType gtype;
if (gtypes.Contains (type)) lock (types) {
return (GType)gtypes[type]; if (gtypes.Contains (type))
return (GType)gtypes[type];
}
if (type.IsSubclassOf (typeof (GLib.Object))) { if (type.IsSubclassOf (typeof (GLib.Object))) {
gtype = GLib.Object.LookupGType (type); gtype = GLib.Object.LookupGType (type);
@ -181,8 +185,10 @@ namespace GLib {
public static Type LookupType (IntPtr typeid) public static Type LookupType (IntPtr typeid)
{ {
if (types.Contains (typeid)) lock (types) {
return (Type)types[typeid]; if (types.Contains (typeid))
return (Type)types[typeid];
}
string native_name = Marshaller.Utf8PtrToString (g_type_name (typeid)); string native_name = Marshaller.Utf8PtrToString (g_type_name (typeid));
@ -365,8 +371,10 @@ namespace GLib {
internal static GType LookupGObjectType (System.Type t) internal static GType LookupGObjectType (System.Type t)
{ {
if (gtypes.Contains (t)) lock (types) {
return (GType) gtypes [t]; if (gtypes.Contains (t))
return (GType) gtypes [t];
}
PropertyInfo pi = t.GetProperty ("GType", BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public); PropertyInfo pi = t.GetProperty ("GType", BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public);
if (pi != null) if (pi != null)