[refactor] RuntimeApi中设置hybridclr参数的功能统一通过GetRuntimeOption和SetRuntimeOption函数

main
walon 2023-12-22 12:24:09 +08:00
parent 9b269ea4c2
commit 7c29ab804b
3 changed files with 52 additions and 27 deletions

View File

@ -11,11 +11,6 @@ namespace HybridCLR
{ {
public static class RuntimeApi public static class RuntimeApi
{ {
#if UNITY_EDITOR
private static int s_interpreterThreadObjectStackSize = 128 * 1024;
private static int s_interpreterThreadFrameStackSize = 2 * 1024;
#endif
/// <summary> /// <summary>
/// 加载补充元数据assembly /// 加载补充元数据assembly
/// </summary> /// </summary>
@ -36,55 +31,65 @@ namespace HybridCLR
/// 获取解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小) /// 获取解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小)
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
#if UNITY_EDITOR
public static int GetInterpreterThreadObjectStackSize() public static int GetInterpreterThreadObjectStackSize()
{ {
return s_interpreterThreadObjectStackSize; return GetRuntimeOption(RuntimeOptionId.InterpreterThreadObjectStackSize);
} }
#else
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern int GetInterpreterThreadObjectStackSize();
#endif
/// <summary> /// <summary>
/// 设置解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小) /// 设置解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小)
/// </summary> /// </summary>
/// <param name="size"></param> /// <param name="size"></param>
#if UNITY_EDITOR
public static void SetInterpreterThreadObjectStackSize(int size) public static void SetInterpreterThreadObjectStackSize(int size)
{ {
s_interpreterThreadObjectStackSize = size; SetRuntimeOption(RuntimeOptionId.InterpreterThreadObjectStackSize, size);
} }
#else
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void SetInterpreterThreadObjectStackSize(int size);
#endif
/// <summary> /// <summary>
/// 获取解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小) /// 获取解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小)
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
#if UNITY_EDITOR
public static int GetInterpreterThreadFrameStackSize() public static int GetInterpreterThreadFrameStackSize()
{ {
return s_interpreterThreadFrameStackSize; return GetRuntimeOption(RuntimeOptionId.InterpreterThreadFrameStackSize);
} }
#else
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern int GetInterpreterThreadFrameStackSize();
#endif
/// <summary> /// <summary>
/// 设置解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小) /// 设置解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小)
/// </summary> /// </summary>
/// <param name="size"></param> /// <param name="size"></param>
#if UNITY_EDITOR
public static void SetInterpreterThreadFrameStackSize(int size) public static void SetInterpreterThreadFrameStackSize(int size)
{ {
s_interpreterThreadFrameStackSize = size; SetRuntimeOption(RuntimeOptionId.InterpreterThreadFrameStackSize, size);
}
#if UNITY_EDITOR
private static readonly Dictionary<RuntimeOptionId, int> s_runtimeOptions = new Dictionary<RuntimeOptionId, int>();
public static void SetRuntimeOption(RuntimeOptionId optionId, int value)
{
s_runtimeOptions[optionId] = value;
} }
#else #else
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
public static extern void SetInterpreterThreadFrameStackSize(int size); public static extern void SetRuntimeOption(RuntimeOptionId optionId, int value);
#endif
#if UNITY_EDITOR
public static int GetRuntimeOption(RuntimeOptionId optionId)
{
if (s_runtimeOptions.TryGetValue(optionId, out var value))
{
return value;
}
return 0;
}
#else
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern int GetRuntimeOption(RuntimeOptionId optionId);
#endif #endif
} }
} }

View File

@ -0,0 +1,9 @@
namespace HybridCLR
{
public enum RuntimeOptionId
{
InterpreterThreadObjectStackSize = 1,
InterpreterThreadFrameStackSize = 2,
ThreadExceptionFlowSize = 3,
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 64be598b47302644a96013c74d945653
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: