TaskPoolMonitor -> TaskPool

master
neuecc 2020-05-29 03:58:22 +09:00
parent 21bf08a6b3
commit 24faa34418
13 changed files with 40 additions and 55 deletions

View File

@ -66,7 +66,7 @@ namespace Cysharp.Threading.Tasks
static ThreadPoolWorkItem()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(ThreadPoolWorkItem), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(ThreadPoolWorkItem), () => pool.Size);
}
Action continuation;

View File

@ -236,7 +236,7 @@ namespace NetCoreSandbox
//await c;
foreach (var item in Cysharp.Threading.Tasks.Internal.TaskPoolMonitor.GetCacheSizeInfo())
foreach (var item in Cysharp.Threading.Tasks.Internal.TaskPool.GetCacheSizeInfo())
{
Console.WriteLine(item);
}

View File

@ -57,7 +57,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
static AsyncUniTaskVoid()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(AsyncUniTaskVoid<TStateMachine>), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(AsyncUniTaskVoid<TStateMachine>), () => pool.Size);
}
public AsyncUniTaskVoid<TStateMachine> NextNode { get; set; }
@ -129,7 +129,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
static AsyncUniTask()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(AsyncUniTask<TStateMachine>), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(AsyncUniTask<TStateMachine>), () => pool.Size);
}
bool TryReturn()
@ -240,7 +240,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
static AsyncUniTask()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(AsyncUniTask<TStateMachine, T>), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(AsyncUniTask<TStateMachine, T>), () => pool.Size);
}
bool TryReturn()

View File

@ -37,7 +37,7 @@ namespace Cysharp.Threading.Tasks
static EnumeratorPromise()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(EnumeratorPromise), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(EnumeratorPromise), () => pool.Size);
}
IEnumerator innerEnumerator;

View File

@ -84,7 +84,7 @@ namespace Cysharp.Threading.Tasks
static AsyncOperationHandleConfiguredSource()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(AsyncOperationHandleConfiguredSource), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(AsyncOperationHandleConfiguredSource), () => pool.Size);
}
AsyncOperationHandle handle;
@ -272,7 +272,7 @@ namespace Cysharp.Threading.Tasks
static AsyncOperationHandleConfiguredSource()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(AsyncOperationHandleConfiguredSource<T>), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(AsyncOperationHandleConfiguredSource<T>), () => pool.Size);
}
AsyncOperationHandle<T> handle;

View File

@ -90,7 +90,7 @@ namespace Cysharp.Threading.Tasks
static TweenConfiguredSource()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(TweenConfiguredSource), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(TweenConfiguredSource), () => pool.Size);
}
static readonly Action<object> CancellationCallbackDelegate = CancellationCallback;

View File

@ -11,7 +11,7 @@ namespace Cysharp.Threading.Tasks.Internal
static PooledDelegate()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(PooledDelegate<T>), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(PooledDelegate<T>), () => pool.Size);
}
readonly Action<T> runDelegate;

View File

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

View File

@ -12,6 +12,7 @@ namespace Cysharp.Threading.Tasks.Internal
public static class TaskPool
{
internal static int MaxPoolSize;
static ConcurrentDictionary<Type, Func<int>> sizes = new ConcurrentDictionary<Type, Func<int>>();
static TaskPool()
{
@ -36,6 +37,19 @@ namespace Cysharp.Threading.Tasks.Internal
{
MaxPoolSize = maxPoolSize;
}
public static IEnumerable<(Type, int)> GetCacheSizeInfo()
{
foreach (var item in sizes)
{
yield return (item.Key, item.Value());
}
}
public static void RegisterSizeGetter(Type type, Func<int> getSize)
{
sizes[type] = getSize;
}
}
@ -98,22 +112,4 @@ namespace Cysharp.Threading.Tasks.Internal
return false;
}
}
public static class TaskPoolMonitor
{
static ConcurrentDictionary<Type, Func<int>> sizes = new ConcurrentDictionary<Type, Func<int>>();
public static IEnumerable<(Type, int)> GetCacheSizeInfo()
{
foreach (var item in sizes)
{
yield return (item.Key, item.Value());
}
}
public static void RegisterSizeGetter(Type type, Func<int> getSize)
{
sizes[type] = getSize;
}
}
}

View File

@ -63,7 +63,7 @@ namespace Cysharp.Threading.Tasks
static YieldPromise()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(YieldPromise), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(YieldPromise), () => pool.Size);
}
CancellationToken cancellationToken;
@ -159,7 +159,7 @@ namespace Cysharp.Threading.Tasks
static DelayFramePromise()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(DelayFramePromise), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(DelayFramePromise), () => pool.Size);
}
int delayFrameCount;
@ -266,7 +266,7 @@ namespace Cysharp.Threading.Tasks
static DelayPromise()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(DelayPromise), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(DelayPromise), () => pool.Size);
}
float delayFrameTimeSpan;
@ -374,7 +374,7 @@ namespace Cysharp.Threading.Tasks
static DelayIgnoreTimeScalePromise()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(DelayIgnoreTimeScalePromise), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(DelayIgnoreTimeScalePromise), () => pool.Size);
}
float delayFrameTimeSpan;

View File

@ -42,7 +42,7 @@ namespace Cysharp.Threading.Tasks
static WaitUntilPromise()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(WaitUntilPromise), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(WaitUntilPromise), () => pool.Size);
}
Func<bool> predicate;
@ -154,7 +154,7 @@ namespace Cysharp.Threading.Tasks
static WaitWhilePromise()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(WaitWhilePromise), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(WaitWhilePromise), () => pool.Size);
}
Func<bool> predicate;
@ -266,7 +266,7 @@ namespace Cysharp.Threading.Tasks
static WaitUntilCanceledPromise()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(WaitUntilCanceledPromise), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(WaitUntilCanceledPromise), () => pool.Size);
}
CancellationToken cancellationToken;
@ -362,7 +362,7 @@ namespace Cysharp.Threading.Tasks
static WaitUntilValueChangedUnityObjectPromise()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(WaitUntilValueChangedUnityObjectPromise<T, U>), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(WaitUntilValueChangedUnityObjectPromise<T, U>), () => pool.Size);
}
T target;
@ -493,7 +493,7 @@ namespace Cysharp.Threading.Tasks
static WaitUntilValueChangedStandardObjectPromise()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(WaitUntilValueChangedStandardObjectPromise<T, U>), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(WaitUntilValueChangedStandardObjectPromise<T, U>), () => pool.Size);
}
WeakReference<T> target;

View File

@ -382,7 +382,7 @@ namespace Cysharp.Threading.Tasks
static AutoResetUniTaskCompletionSource()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(AutoResetUniTaskCompletionSource), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(AutoResetUniTaskCompletionSource), () => pool.Size);
}
UniTaskCompletionSourceCore<AsyncUnit> core;
@ -608,7 +608,7 @@ namespace Cysharp.Threading.Tasks
static AutoResetUniTaskCompletionSource()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(AutoResetUniTaskCompletionSource<T>), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(AutoResetUniTaskCompletionSource<T>), () => pool.Size);
}
UniTaskCompletionSourceCore<T> core;

View File

@ -82,7 +82,7 @@ namespace Cysharp.Threading.Tasks
static AsyncOperationConfiguredSource()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(AsyncOperationConfiguredSource), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(AsyncOperationConfiguredSource), () => pool.Size);
}
AsyncOperation asyncOperation;
@ -264,7 +264,7 @@ namespace Cysharp.Threading.Tasks
static ResourceRequestConfiguredSource()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(ResourceRequestConfiguredSource), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(ResourceRequestConfiguredSource), () => pool.Size);
}
ResourceRequest asyncOperation;
@ -451,7 +451,7 @@ namespace Cysharp.Threading.Tasks
static AssetBundleRequestConfiguredSource()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(AssetBundleRequestConfiguredSource), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(AssetBundleRequestConfiguredSource), () => pool.Size);
}
AssetBundleRequest asyncOperation;
@ -637,7 +637,7 @@ namespace Cysharp.Threading.Tasks
static AssetBundleCreateRequestConfiguredSource()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(AssetBundleCreateRequestConfiguredSource), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(AssetBundleCreateRequestConfiguredSource), () => pool.Size);
}
AssetBundleCreateRequest asyncOperation;
@ -824,7 +824,7 @@ namespace Cysharp.Threading.Tasks
static UnityWebRequestAsyncOperationConfiguredSource()
{
TaskPoolMonitor.RegisterSizeGetter(typeof(UnityWebRequestAsyncOperationConfiguredSource), () => pool.Size);
TaskPool.RegisterSizeGetter(typeof(UnityWebRequestAsyncOperationConfiguredSource), () => pool.Size);
}
UnityWebRequestAsyncOperation asyncOperation;