logging
parent
7289fe6e25
commit
859c4d706f
|
@ -12,7 +12,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
[StructLayout(LayoutKind.Auto)]
|
[StructLayout(LayoutKind.Auto)]
|
||||||
public struct AsyncUniTaskMethodBuilder
|
public struct AsyncUniTaskMethodBuilder
|
||||||
{
|
{
|
||||||
internal IStateMachineRunnerPromise runnerPromise;
|
IStateMachineRunnerPromise runnerPromise;
|
||||||
Exception ex;
|
Exception ex;
|
||||||
|
|
||||||
// 1. Static Create method.
|
// 1. Static Create method.
|
||||||
|
@ -80,7 +80,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
{
|
{
|
||||||
if (runnerPromise == null)
|
if (runnerPromise == null)
|
||||||
{
|
{
|
||||||
AsyncUniTask<TStateMachine>.SetStateMachine(ref this, ref stateMachine);
|
AsyncUniTask<TStateMachine>.SetStateMachine(ref stateMachine, ref runnerPromise);
|
||||||
}
|
}
|
||||||
|
|
||||||
awaiter.OnCompleted(runnerPromise.MoveNext);
|
awaiter.OnCompleted(runnerPromise.MoveNext);
|
||||||
|
@ -96,7 +96,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
{
|
{
|
||||||
if (runnerPromise == null)
|
if (runnerPromise == null)
|
||||||
{
|
{
|
||||||
AsyncUniTask<TStateMachine>.SetStateMachine(ref this, ref stateMachine);
|
AsyncUniTask<TStateMachine>.SetStateMachine(ref stateMachine, ref runnerPromise);
|
||||||
}
|
}
|
||||||
|
|
||||||
awaiter.UnsafeOnCompleted(runnerPromise.MoveNext);
|
awaiter.UnsafeOnCompleted(runnerPromise.MoveNext);
|
||||||
|
@ -138,7 +138,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
[StructLayout(LayoutKind.Auto)]
|
[StructLayout(LayoutKind.Auto)]
|
||||||
public struct AsyncUniTaskMethodBuilder<T>
|
public struct AsyncUniTaskMethodBuilder<T>
|
||||||
{
|
{
|
||||||
internal IStateMachineRunnerPromise<T> runnerPromise;
|
IStateMachineRunnerPromise<T> runnerPromise;
|
||||||
Exception ex;
|
Exception ex;
|
||||||
T result;
|
T result;
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
{
|
{
|
||||||
if (runnerPromise == null)
|
if (runnerPromise == null)
|
||||||
{
|
{
|
||||||
AsyncUniTask<TStateMachine, T>.SetStateMachine(ref this, ref stateMachine);
|
AsyncUniTask<TStateMachine, T>.SetStateMachine(ref stateMachine, ref runnerPromise);
|
||||||
}
|
}
|
||||||
|
|
||||||
awaiter.OnCompleted(runnerPromise.MoveNext);
|
awaiter.OnCompleted(runnerPromise.MoveNext);
|
||||||
|
@ -227,7 +227,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
{
|
{
|
||||||
if (runnerPromise == null)
|
if (runnerPromise == null)
|
||||||
{
|
{
|
||||||
AsyncUniTask<TStateMachine, T>.SetStateMachine(ref this, ref stateMachine);
|
AsyncUniTask<TStateMachine, T>.SetStateMachine(ref stateMachine, ref runnerPromise);
|
||||||
}
|
}
|
||||||
|
|
||||||
awaiter.UnsafeOnCompleted(runnerPromise.MoveNext);
|
awaiter.UnsafeOnCompleted(runnerPromise.MoveNext);
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
[StructLayout(LayoutKind.Auto)]
|
[StructLayout(LayoutKind.Auto)]
|
||||||
public struct AsyncUniTaskVoidMethodBuilder
|
public struct AsyncUniTaskVoidMethodBuilder
|
||||||
{
|
{
|
||||||
internal IStateMachineRunner runner;
|
IStateMachineRunner runner;
|
||||||
|
|
||||||
// 1. Static Create method.
|
// 1. Static Create method.
|
||||||
[DebuggerHidden]
|
[DebuggerHidden]
|
||||||
|
@ -70,7 +70,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
{
|
{
|
||||||
if (runner == null)
|
if (runner == null)
|
||||||
{
|
{
|
||||||
AsyncUniTaskVoid<TStateMachine>.SetStateMachine(ref this, ref stateMachine);
|
AsyncUniTaskVoid<TStateMachine>.SetStateMachine(ref stateMachine, ref runner);
|
||||||
}
|
}
|
||||||
|
|
||||||
awaiter.OnCompleted(runner.MoveNext);
|
awaiter.OnCompleted(runner.MoveNext);
|
||||||
|
@ -86,7 +86,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
{
|
{
|
||||||
if (runner == null)
|
if (runner == null)
|
||||||
{
|
{
|
||||||
AsyncUniTaskVoid<TStateMachine>.SetStateMachine(ref this, ref stateMachine);
|
AsyncUniTaskVoid<TStateMachine>.SetStateMachine(ref stateMachine, ref runner);
|
||||||
}
|
}
|
||||||
|
|
||||||
awaiter.UnsafeOnCompleted(runner.MoveNext);
|
awaiter.UnsafeOnCompleted(runner.MoveNext);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
using Cysharp.Threading.Tasks.Internal;
|
using Cysharp.Threading.Tasks.Internal;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
@ -29,6 +30,16 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
void SetException(Exception exception);
|
void SetException(Exception exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static class StateMachineUtility
|
||||||
|
{
|
||||||
|
public static int GetState(IAsyncStateMachine stateMachine)
|
||||||
|
{
|
||||||
|
var info = stateMachine.GetType().GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
|
||||||
|
.First(x => x.Name.EndsWith("__state"));
|
||||||
|
return (int)info.GetValue(stateMachine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal sealed class AsyncUniTaskVoid<TStateMachine> : IStateMachineRunner, ITaskPoolNode<AsyncUniTaskVoid<TStateMachine>>, IUniTaskSource
|
internal sealed class AsyncUniTaskVoid<TStateMachine> : IStateMachineRunner, ITaskPoolNode<AsyncUniTaskVoid<TStateMachine>>, IUniTaskSource
|
||||||
where TStateMachine : IAsyncStateMachine
|
where TStateMachine : IAsyncStateMachine
|
||||||
{
|
{
|
||||||
|
@ -43,7 +54,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
MoveNext = Run;
|
MoveNext = Run;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetStateMachine(ref AsyncUniTaskVoidMethodBuilder builder, ref TStateMachine stateMachine)
|
public static void SetStateMachine(ref TStateMachine stateMachine, ref IStateMachineRunner runnerFieldRef)
|
||||||
{
|
{
|
||||||
if (!pool.TryPop(out var result))
|
if (!pool.TryPop(out var result))
|
||||||
{
|
{
|
||||||
|
@ -51,7 +62,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
}
|
}
|
||||||
TaskTracker.TrackActiveTask(result, 3);
|
TaskTracker.TrackActiveTask(result, 3);
|
||||||
|
|
||||||
builder.runner = result; // set runner before copied.
|
runnerFieldRef = result; // set runner before copied.
|
||||||
result.stateMachine = stateMachine; // copy struct StateMachine(in release build).
|
result.stateMachine = stateMachine; // copy struct StateMachine(in release build).
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +124,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
MoveNext = Run;
|
MoveNext = Run;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetStateMachine(ref AsyncUniTaskMethodBuilder builder, ref TStateMachine stateMachine)
|
public static void SetStateMachine(ref TStateMachine stateMachine, ref IStateMachineRunnerPromise runnerPromiseFieldRef)
|
||||||
{
|
{
|
||||||
if (!pool.TryPop(out var result))
|
if (!pool.TryPop(out var result))
|
||||||
{
|
{
|
||||||
|
@ -121,7 +132,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
}
|
}
|
||||||
TaskTracker.TrackActiveTask(result, 3);
|
TaskTracker.TrackActiveTask(result, 3);
|
||||||
|
|
||||||
builder.runnerPromise = result; // set runner before copied.
|
runnerPromiseFieldRef = result; // set runner before copied.
|
||||||
result.stateMachine = stateMachine; // copy struct StateMachine(in release build).
|
result.stateMachine = stateMachine; // copy struct StateMachine(in release build).
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +235,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
MoveNext = Run;
|
MoveNext = Run;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetStateMachine(ref AsyncUniTaskMethodBuilder<T> builder, ref TStateMachine stateMachine)
|
public static void SetStateMachine(ref TStateMachine stateMachine, ref IStateMachineRunnerPromise<T> runnerPromiseFieldRef)
|
||||||
{
|
{
|
||||||
if (!pool.TryPop(out var result))
|
if (!pool.TryPop(out var result))
|
||||||
{
|
{
|
||||||
|
@ -232,10 +243,12 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
}
|
}
|
||||||
TaskTracker.TrackActiveTask(result, 3);
|
TaskTracker.TrackActiveTask(result, 3);
|
||||||
|
|
||||||
builder.runnerPromise = result; // set runner before copied.
|
runnerPromiseFieldRef = result; // set runner before copied.
|
||||||
result.stateMachine = stateMachine; // copy struct StateMachine(in release build).
|
result.stateMachine = stateMachine; // copy struct StateMachine(in release build).
|
||||||
|
UnityEngine.Debug.Log($"SetStateMachine State:" + StateMachineUtility.GetState(stateMachine));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public AsyncUniTask<TStateMachine, T> NextNode { get; set; }
|
public AsyncUniTask<TStateMachine, T> NextNode { get; set; }
|
||||||
|
|
||||||
static AsyncUniTask()
|
static AsyncUniTask()
|
||||||
|
@ -255,6 +268,7 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
void Run()
|
void Run()
|
||||||
{
|
{
|
||||||
|
UnityEngine.Debug.Log($"MoveNext State:" + StateMachineUtility.GetState(stateMachine));
|
||||||
stateMachine.MoveNext();
|
stateMachine.MoveNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||||
{
|
{
|
||||||
internal static async UniTask<TSource[]> ToArrayAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
internal static async UniTask<TSource[]> ToArrayAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
UnityEngine.Debug.Log("Called ToArray");
|
||||||
|
|
||||||
var pool = ArrayPool<TSource>.Shared;
|
var pool = ArrayPool<TSource>.Shared;
|
||||||
var array = pool.Rent(16);
|
var array = pool.Rent(16);
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 370f60b2e4cd92d4faafda153c9c5f8a
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue