Use ref T for ITaskPoolNode<T>.NextNode

pull/148/head
RamType0 2020-08-28 18:03:22 +09:00
parent a65f4da7a2
commit 3bb446556a
13 changed files with 74 additions and 38 deletions

View File

@ -62,7 +62,8 @@ namespace Cysharp.Threading.Tasks
sealed class ThreadPoolWorkItem : IThreadPoolWorkItem, ITaskPoolNode<ThreadPoolWorkItem>
{
static TaskPool<ThreadPoolWorkItem> pool;
public ThreadPoolWorkItem NextNode { get; set; }
ThreadPoolWorkItem nextNode;
public ref ThreadPoolWorkItem NextNode => ref nextNode;
static ThreadPoolWorkItem()
{

View File

@ -87,7 +87,8 @@ namespace Cysharp.Threading.Tasks
static Action<object> cancellationCallback = CancellationCallback;
static TaskPool<WaitAsyncSource> pool;
WaitAsyncSource ITaskPoolNode<WaitAsyncSource>.NextNode { get; set; }
WaitAsyncSource nextNode;
ref WaitAsyncSource ITaskPoolNode<WaitAsyncSource>.NextNode => ref nextNode;
static WaitAsyncSource()
{
@ -404,7 +405,8 @@ namespace Cysharp.Threading.Tasks
static Action<object> cancellationCallback = CancellationCallback;
static TaskPool<WaitAsyncSource> pool;
WaitAsyncSource ITaskPoolNode<WaitAsyncSource>.NextNode { get; set; }
WaitAsyncSource nextNode;
ref WaitAsyncSource ITaskPoolNode<WaitAsyncSource>.NextNode => ref nextNode;
static WaitAsyncSource()
{

View File

@ -87,7 +87,8 @@ namespace Cysharp.Threading.Tasks.CompilerServices
TaskPool.RegisterSizeGetter(typeof(AsyncUniTaskVoid<TStateMachine>), () => pool.Size);
}
public AsyncUniTaskVoid<TStateMachine> NextNode { get; set; }
AsyncUniTaskVoid<TStateMachine> nextNode;
public ref AsyncUniTaskVoid<TStateMachine> NextNode => ref nextNode;
public void Return()
{
@ -157,7 +158,8 @@ namespace Cysharp.Threading.Tasks.CompilerServices
result.stateMachine = stateMachine; // copy struct StateMachine(in release build).
}
public AsyncUniTask<TStateMachine> NextNode { get; set; }
AsyncUniTask<TStateMachine> nextNode;
public ref AsyncUniTask<TStateMachine> NextNode => ref nextNode;
static AsyncUniTask()
{
@ -279,7 +281,8 @@ namespace Cysharp.Threading.Tasks.CompilerServices
result.stateMachine = stateMachine; // copy struct StateMachine(in release build).
}
public AsyncUniTask<TStateMachine, T> NextNode { get; set; }
AsyncUniTask<TStateMachine, T> nextNode;
public ref AsyncUniTask<TStateMachine, T> NextNode => ref nextNode;
static AsyncUniTask()
{

View File

@ -35,7 +35,8 @@ namespace Cysharp.Threading.Tasks
sealed class EnumeratorPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<EnumeratorPromise>
{
static TaskPool<EnumeratorPromise> pool;
public EnumeratorPromise NextNode { get; set; }
EnumeratorPromise nextNode;
public ref EnumeratorPromise NextNode => ref nextNode;
static EnumeratorPromise()
{

View File

@ -7,7 +7,8 @@ namespace Cysharp.Threading.Tasks.Internal
{
static TaskPool<PooledDelegate<T>> pool;
public PooledDelegate<T> NextNode { get; set; }
PooledDelegate<T> nextNode;
public ref PooledDelegate<T> NextNode => ref nextNode;
static PooledDelegate()
{

View File

@ -55,7 +55,7 @@ namespace Cysharp.Threading.Tasks
public interface ITaskPoolNode<T>
{
T NextNode { get; set; }
ref T NextNode { get; }
}
// mutable struct, don't mark readonly.
@ -77,8 +77,9 @@ namespace Cysharp.Threading.Tasks
var v = root;
if (!(v is null))
{
root = v.NextNode;
v.NextNode = null;
ref var nextNode = ref v.NextNode;
root = nextNode;
nextNode = null;
size--;
result = v;
Volatile.Write(ref gate, 0);

View File

@ -127,7 +127,8 @@ namespace Cysharp.Threading.Tasks
sealed class YieldPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<YieldPromise>
{
static TaskPool<YieldPromise> pool;
public YieldPromise NextNode { get; set; }
YieldPromise nextNode;
public ref YieldPromise NextNode => ref nextNode;
static YieldPromise()
{
@ -215,7 +216,8 @@ namespace Cysharp.Threading.Tasks
sealed class NextFramePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<NextFramePromise>
{
static TaskPool<NextFramePromise> pool;
public NextFramePromise NextNode { get; set; }
NextFramePromise nextNode;
public ref NextFramePromise NextNode => ref nextNode;
static NextFramePromise()
{
@ -309,7 +311,8 @@ namespace Cysharp.Threading.Tasks
sealed class DelayFramePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<DelayFramePromise>
{
static TaskPool<DelayFramePromise> pool;
public DelayFramePromise NextNode { get; set; }
DelayFramePromise nextNode;
public ref DelayFramePromise NextNode => ref nextNode;
static DelayFramePromise()
{
@ -424,7 +427,8 @@ namespace Cysharp.Threading.Tasks
sealed class DelayPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<DelayPromise>
{
static TaskPool<DelayPromise> pool;
public DelayPromise NextNode { get; set; }
DelayPromise nextNode;
public ref DelayPromise NextNode => ref nextNode;
static DelayPromise()
{
@ -534,7 +538,8 @@ namespace Cysharp.Threading.Tasks
sealed class DelayIgnoreTimeScalePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<DelayIgnoreTimeScalePromise>
{
static TaskPool<DelayIgnoreTimeScalePromise> pool;
public DelayIgnoreTimeScalePromise NextNode { get; set; }
DelayIgnoreTimeScalePromise nextNode;
public ref DelayIgnoreTimeScalePromise NextNode => ref nextNode;
static DelayIgnoreTimeScalePromise()
{
@ -644,7 +649,8 @@ namespace Cysharp.Threading.Tasks
sealed class DelayRealtimePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<DelayRealtimePromise>
{
static TaskPool<DelayRealtimePromise> pool;
public DelayRealtimePromise NextNode { get; set; }
DelayRealtimePromise nextNode;
public ref DelayRealtimePromise NextNode => ref nextNode;
static DelayRealtimePromise()
{

View File

@ -224,7 +224,8 @@ namespace Cysharp.Threading.Tasks
sealed class ThreadPoolWorkItem : IThreadPoolWorkItem, ITaskPoolNode<ThreadPoolWorkItem>
{
static TaskPool<ThreadPoolWorkItem> pool;
public ThreadPoolWorkItem NextNode { get; set; }
ThreadPoolWorkItem nextNode;
public ref ThreadPoolWorkItem NextNode => ref nextNode;
static ThreadPoolWorkItem()
{

View File

@ -38,7 +38,8 @@ namespace Cysharp.Threading.Tasks
sealed class WaitUntilPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<WaitUntilPromise>
{
static TaskPool<WaitUntilPromise> pool;
public WaitUntilPromise NextNode { get; set; }
WaitUntilPromise nextNode;
public ref WaitUntilPromise NextNode => ref nextNode;
static WaitUntilPromise()
{
@ -142,7 +143,8 @@ namespace Cysharp.Threading.Tasks
sealed class WaitWhilePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<WaitWhilePromise>
{
static TaskPool<WaitWhilePromise> pool;
public WaitWhilePromise NextNode { get; set; }
WaitWhilePromise nextNode;
public ref WaitWhilePromise NextNode => ref nextNode;
static WaitWhilePromise()
{
@ -246,7 +248,8 @@ namespace Cysharp.Threading.Tasks
sealed class WaitUntilCanceledPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<WaitUntilCanceledPromise>
{
static TaskPool<WaitUntilCanceledPromise> pool;
public WaitUntilCanceledPromise NextNode { get; set; }
WaitUntilCanceledPromise nextNode;
public ref WaitUntilCanceledPromise NextNode => ref nextNode;
static WaitUntilCanceledPromise()
{
@ -334,7 +337,8 @@ namespace Cysharp.Threading.Tasks
sealed class WaitUntilValueChangedUnityObjectPromise<T, U> : IUniTaskSource<U>, IPlayerLoopItem, ITaskPoolNode<WaitUntilValueChangedUnityObjectPromise<T, U>>
{
static TaskPool<WaitUntilValueChangedUnityObjectPromise<T, U>> pool;
public WaitUntilValueChangedUnityObjectPromise<T, U> NextNode { get; set; }
WaitUntilValueChangedUnityObjectPromise<T, U> nextNode;
public ref WaitUntilValueChangedUnityObjectPromise<T, U> NextNode => ref nextNode;
static WaitUntilValueChangedUnityObjectPromise()
{
@ -457,7 +461,8 @@ namespace Cysharp.Threading.Tasks
where T : class
{
static TaskPool<WaitUntilValueChangedStandardObjectPromise<T, U>> pool;
public WaitUntilValueChangedStandardObjectPromise<T, U> NextNode { get; set; }
WaitUntilValueChangedStandardObjectPromise<T, U> nextNode;
public ref WaitUntilValueChangedStandardObjectPromise<T, U> NextNode => ref nextNode;
static WaitUntilValueChangedStandardObjectPromise()
{

View File

@ -319,7 +319,8 @@ namespace Cysharp.Threading.Tasks
public class AutoResetUniTaskCompletionSource : IUniTaskSource, ITaskPoolNode<AutoResetUniTaskCompletionSource>, IPromise
{
static TaskPool<AutoResetUniTaskCompletionSource> pool;
public AutoResetUniTaskCompletionSource NextNode { get; set; }
AutoResetUniTaskCompletionSource nextNode;
public ref AutoResetUniTaskCompletionSource NextNode => ref nextNode;
static AutoResetUniTaskCompletionSource()
{
@ -441,7 +442,8 @@ namespace Cysharp.Threading.Tasks
public class AutoResetUniTaskCompletionSource<T> : IUniTaskSource<T>, ITaskPoolNode<AutoResetUniTaskCompletionSource<T>>, IPromise<T>
{
static TaskPool<AutoResetUniTaskCompletionSource<T>> pool;
public AutoResetUniTaskCompletionSource<T> NextNode { get; set; }
AutoResetUniTaskCompletionSource<T> nextNode;
public ref AutoResetUniTaskCompletionSource<T> NextNode => ref nextNode;
static AutoResetUniTaskCompletionSource()
{

View File

@ -82,7 +82,8 @@ namespace Cysharp.Threading.Tasks
sealed class AssetBundleRequestAllAssetsWithCancellationSource : IUniTaskSource<UnityEngine.Object[]>, IPlayerLoopItem, ITaskPoolNode<AssetBundleRequestAllAssetsWithCancellationSource>
{
static TaskPool<AssetBundleRequestAllAssetsWithCancellationSource> pool;
public AssetBundleRequestAllAssetsWithCancellationSource NextNode { get; set; }
AssetBundleRequestAllAssetsWithCancellationSource nextNode;
public ref AssetBundleRequestAllAssetsWithCancellationSource NextNode => ref nextNode;
static AssetBundleRequestAllAssetsWithCancellationSource()
{
@ -204,7 +205,8 @@ namespace Cysharp.Threading.Tasks
sealed class AssetBundleRequestAllAssetsConfiguredSource : IUniTaskSource<UnityEngine.Object[]>, IPlayerLoopItem, ITaskPoolNode<AssetBundleRequestAllAssetsConfiguredSource>
{
static TaskPool<AssetBundleRequestAllAssetsConfiguredSource> pool;
public AssetBundleRequestAllAssetsConfiguredSource NextNode { get; set; }
AssetBundleRequestAllAssetsConfiguredSource nextNode;
public ref AssetBundleRequestAllAssetsConfiguredSource NextNode => ref nextNode;
static AssetBundleRequestAllAssetsConfiguredSource()
{

View File

@ -29,7 +29,8 @@ namespace Cysharp.Threading.Tasks
sealed class AsyncGPUReadbackRequestAwaiterConfiguredSource : IUniTaskSource<AsyncGPUReadbackRequest>, IPlayerLoopItem, ITaskPoolNode<AsyncGPUReadbackRequestAwaiterConfiguredSource>
{
static TaskPool<AsyncGPUReadbackRequestAwaiterConfiguredSource> pool;
public AsyncGPUReadbackRequestAwaiterConfiguredSource NextNode { get; set; }
AsyncGPUReadbackRequestAwaiterConfiguredSource nextNode;
public ref AsyncGPUReadbackRequestAwaiterConfiguredSource NextNode => ref nextNode;
static AsyncGPUReadbackRequestAwaiterConfiguredSource()
{

View File

@ -80,7 +80,8 @@ namespace Cysharp.Threading.Tasks
sealed class AsyncOperationWithCancellationSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<AsyncOperationWithCancellationSource>
{
static TaskPool<AsyncOperationWithCancellationSource> pool;
public AsyncOperationWithCancellationSource NextNode { get; set; }
AsyncOperationWithCancellationSource nextNode;
public ref AsyncOperationWithCancellationSource NextNode => ref nextNode;
static AsyncOperationWithCancellationSource()
{
@ -198,7 +199,8 @@ namespace Cysharp.Threading.Tasks
sealed class AsyncOperationConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<AsyncOperationConfiguredSource>
{
static TaskPool<AsyncOperationConfiguredSource> pool;
public AsyncOperationConfiguredSource NextNode { get; set; }
AsyncOperationConfiguredSource nextNode;
public ref AsyncOperationConfiguredSource NextNode => ref nextNode;
static AsyncOperationConfiguredSource()
{
@ -374,7 +376,8 @@ namespace Cysharp.Threading.Tasks
sealed class ResourceRequestWithCancellationSource : IUniTaskSource<UnityEngine.Object>, IPlayerLoopItem, ITaskPoolNode<ResourceRequestWithCancellationSource>
{
static TaskPool<ResourceRequestWithCancellationSource> pool;
public ResourceRequestWithCancellationSource NextNode { get; set; }
ResourceRequestWithCancellationSource nextNode;
public ref ResourceRequestWithCancellationSource NextNode => ref nextNode;
static ResourceRequestWithCancellationSource()
{
@ -496,7 +499,8 @@ namespace Cysharp.Threading.Tasks
sealed class ResourceRequestConfiguredSource : IUniTaskSource<UnityEngine.Object>, IPlayerLoopItem, ITaskPoolNode<ResourceRequestConfiguredSource>
{
static TaskPool<ResourceRequestConfiguredSource> pool;
public ResourceRequestConfiguredSource NextNode { get; set; }
ResourceRequestConfiguredSource nextNode;
public ref ResourceRequestConfiguredSource NextNode => ref nextNode;
static ResourceRequestConfiguredSource()
{
@ -677,7 +681,8 @@ namespace Cysharp.Threading.Tasks
sealed class AssetBundleRequestWithCancellationSource : IUniTaskSource<UnityEngine.Object>, IPlayerLoopItem, ITaskPoolNode<AssetBundleRequestWithCancellationSource>
{
static TaskPool<AssetBundleRequestWithCancellationSource> pool;
public AssetBundleRequestWithCancellationSource NextNode { get; set; }
AssetBundleRequestWithCancellationSource nextNode;
public ref AssetBundleRequestWithCancellationSource NextNode => ref nextNode;
static AssetBundleRequestWithCancellationSource()
{
@ -799,7 +804,8 @@ namespace Cysharp.Threading.Tasks
sealed class AssetBundleRequestConfiguredSource : IUniTaskSource<UnityEngine.Object>, IPlayerLoopItem, ITaskPoolNode<AssetBundleRequestConfiguredSource>
{
static TaskPool<AssetBundleRequestConfiguredSource> pool;
public AssetBundleRequestConfiguredSource NextNode { get; set; }
AssetBundleRequestConfiguredSource nextNode;
public ref AssetBundleRequestConfiguredSource NextNode => ref nextNode;
static AssetBundleRequestConfiguredSource()
{
@ -981,7 +987,8 @@ namespace Cysharp.Threading.Tasks
sealed class AssetBundleCreateRequestWithCancellationSource : IUniTaskSource<AssetBundle>, IPlayerLoopItem, ITaskPoolNode<AssetBundleCreateRequestWithCancellationSource>
{
static TaskPool<AssetBundleCreateRequestWithCancellationSource> pool;
public AssetBundleCreateRequestWithCancellationSource NextNode { get; set; }
AssetBundleCreateRequestWithCancellationSource nextNode;
public ref AssetBundleCreateRequestWithCancellationSource NextNode => ref nextNode;
static AssetBundleCreateRequestWithCancellationSource()
{
@ -1103,7 +1110,8 @@ namespace Cysharp.Threading.Tasks
sealed class AssetBundleCreateRequestConfiguredSource : IUniTaskSource<AssetBundle>, IPlayerLoopItem, ITaskPoolNode<AssetBundleCreateRequestConfiguredSource>
{
static TaskPool<AssetBundleCreateRequestConfiguredSource> pool;
public AssetBundleCreateRequestConfiguredSource NextNode { get; set; }
AssetBundleCreateRequestConfiguredSource nextNode;
public ref AssetBundleCreateRequestConfiguredSource NextNode => ref nextNode;
static AssetBundleCreateRequestConfiguredSource()
{
@ -1307,7 +1315,8 @@ namespace Cysharp.Threading.Tasks
sealed class UnityWebRequestAsyncOperationWithCancellationSource : IUniTaskSource<UnityWebRequest>, IPlayerLoopItem, ITaskPoolNode<UnityWebRequestAsyncOperationWithCancellationSource>
{
static TaskPool<UnityWebRequestAsyncOperationWithCancellationSource> pool;
public UnityWebRequestAsyncOperationWithCancellationSource NextNode { get; set; }
UnityWebRequestAsyncOperationWithCancellationSource nextNode;
public ref UnityWebRequestAsyncOperationWithCancellationSource NextNode => ref nextNode;
static UnityWebRequestAsyncOperationWithCancellationSource()
{
@ -1438,7 +1447,8 @@ namespace Cysharp.Threading.Tasks
sealed class UnityWebRequestAsyncOperationConfiguredSource : IUniTaskSource<UnityWebRequest>, IPlayerLoopItem, ITaskPoolNode<UnityWebRequestAsyncOperationConfiguredSource>
{
static TaskPool<UnityWebRequestAsyncOperationConfiguredSource> pool;
public UnityWebRequestAsyncOperationConfiguredSource NextNode { get; set; }
UnityWebRequestAsyncOperationConfiguredSource nextNode;
public ref UnityWebRequestAsyncOperationConfiguredSource NextNode => ref nextNode;
static UnityWebRequestAsyncOperationConfiguredSource()
{