зеркало из https://github.com/mono/ikvm-fork.git
Use double checked locking to avoid taking the lock in the common case when accessing TypeWrapper.ClassObject.
This commit is contained in:
Родитель
95c07f04c3
Коммит
6fd6fc2f3b
|
@ -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)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче