Use double checked locking to avoid taking the lock in the common case when accessing TypeWrapper.ClassObject.

This commit is contained in:
jfrijters 2009-02-24 04:42:20 +00:00
Родитель 95c07f04c3
Коммит 6fd6fc2f3b
1 изменённых файлов: 21 добавлений и 13 удалений

Просмотреть файл

@ -2065,25 +2065,33 @@ namespace IKVM.Internal
get
{
Debug.Assert(!IsUnloadable && !IsVerifierType);
lock(this)
if (classObject == null)
{
if(classObject == null)
{
#if !COMPACT_FRAMEWORK
// DynamicTypeWrapper should haved already had SetClassObject explicitly
Debug.Assert(!(this is DynamicTypeWrapper));
#endif // !COMPACT_FRAMEWORK
#if !FIRST_PASS
java.lang.Class clazz = java.lang.Class.newClass();
SetTypeWrapperHack(ref clazz.typeWrapper, this);
classObject = clazz;
#endif
}
LazyInitClass();
}
return classObject;
}
}
private void LazyInitClass()
{
lock (this)
{
if (classObject == null)
{
#if !COMPACT_FRAMEWORK
// DynamicTypeWrapper should haved already had SetClassObject explicitly
Debug.Assert(!(this is DynamicTypeWrapper));
#endif // !COMPACT_FRAMEWORK
#if !FIRST_PASS
java.lang.Class clazz = java.lang.Class.newClass();
SetTypeWrapperHack(ref clazz.typeWrapper, this);
System.Threading.Interlocked.Exchange(ref classObject, clazz);
#endif
}
}
}
// MONOBUG this method is to work around an mcs bug
internal static void SetTypeWrapperHack<T>(ref T field, TypeWrapper type)
{