TaskPoolMonitor -> TaskPool

pull/61/head
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() static ThreadPoolWorkItem()
{ {
TaskPoolMonitor.RegisterSizeGetter(typeof(ThreadPoolWorkItem), () => pool.Size); TaskPool.RegisterSizeGetter(typeof(ThreadPoolWorkItem), () => pool.Size);
} }
Action continuation; Action continuation;

View File

@ -236,7 +236,7 @@ namespace NetCoreSandbox
//await c; //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); Console.WriteLine(item);
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -11,7 +11,7 @@ namespace Cysharp.Threading.Tasks.Internal
static PooledDelegate() static PooledDelegate()
{ {
TaskPoolMonitor.RegisterSizeGetter(typeof(PooledDelegate<T>), () => pool.Size); TaskPool.RegisterSizeGetter(typeof(PooledDelegate<T>), () => pool.Size);
} }
readonly Action<T> runDelegate; 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 public static class TaskPool
{ {
internal static int MaxPoolSize; internal static int MaxPoolSize;
static ConcurrentDictionary<Type, Func<int>> sizes = new ConcurrentDictionary<Type, Func<int>>();
static TaskPool() static TaskPool()
{ {
@ -36,6 +37,19 @@ namespace Cysharp.Threading.Tasks.Internal
{ {
MaxPoolSize = maxPoolSize; 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; 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() static YieldPromise()
{ {
TaskPoolMonitor.RegisterSizeGetter(typeof(YieldPromise), () => pool.Size); TaskPool.RegisterSizeGetter(typeof(YieldPromise), () => pool.Size);
} }
CancellationToken cancellationToken; CancellationToken cancellationToken;
@ -159,7 +159,7 @@ namespace Cysharp.Threading.Tasks
static DelayFramePromise() static DelayFramePromise()
{ {
TaskPoolMonitor.RegisterSizeGetter(typeof(DelayFramePromise), () => pool.Size); TaskPool.RegisterSizeGetter(typeof(DelayFramePromise), () => pool.Size);
} }
int delayFrameCount; int delayFrameCount;
@ -266,7 +266,7 @@ namespace Cysharp.Threading.Tasks
static DelayPromise() static DelayPromise()
{ {
TaskPoolMonitor.RegisterSizeGetter(typeof(DelayPromise), () => pool.Size); TaskPool.RegisterSizeGetter(typeof(DelayPromise), () => pool.Size);
} }
float delayFrameTimeSpan; float delayFrameTimeSpan;
@ -374,7 +374,7 @@ namespace Cysharp.Threading.Tasks
static DelayIgnoreTimeScalePromise() static DelayIgnoreTimeScalePromise()
{ {
TaskPoolMonitor.RegisterSizeGetter(typeof(DelayIgnoreTimeScalePromise), () => pool.Size); TaskPool.RegisterSizeGetter(typeof(DelayIgnoreTimeScalePromise), () => pool.Size);
} }
float delayFrameTimeSpan; float delayFrameTimeSpan;

View File

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

View File

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

View File

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