未验证 提交 160fd45f 编写于 作者: J Jan Kotas 提交者: GitHub

Simplify RuntimeType.ClearCache (#51070)

上级 dcf81657
......@@ -26,7 +26,7 @@ public partial struct GCHandle
#endif
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void InternalSet(IntPtr handle, object? value);
internal static extern void InternalSet(IntPtr handle, object? value);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern object? InternalCompareExchange(IntPtr handle, object? value, object? oldValue);
......
......@@ -2426,27 +2426,8 @@ internal void ClearCache()
return;
}
// Loop until the cache is successfully zero'd out.
do
{
// If the GCHandle doesn't wrap a cache yet, there's nothing more to do.
RuntimeTypeCache? existingCache = (RuntimeTypeCache?)GCHandle.InternalGet(m_cache);
if (existingCache is null)
{
return;
}
// Create a new, empty cache to replace the old one and try to substitute it in.
var newCache = new RuntimeTypeCache(this);
if (ReferenceEquals(GCHandle.InternalCompareExchange(m_cache, newCache, existingCache), existingCache))
{
// We were successful, so there's nothing more to do.
return;
}
// We raced with someone else to initialize the cache. Try again.
}
while (true);
// Set the GCHandle to null. The cache will be re-created next time it is needed.
GCHandle.InternalSet(m_cache, null);
}
private string? GetDefaultMemberName()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册