Make all TCS RunContinuationsAsynchronously

This commit is contained in:
Soreepeong 2024-07-21 20:49:41 +09:00
parent 856c198934
commit 1be5cd452d
14 changed files with 33 additions and 23 deletions

View file

@ -16,10 +16,17 @@ namespace Dalamud.Game.Config;
[ServiceManager.EarlyLoadedService]
internal sealed class GameConfig : IInternalDisposableService, IGameConfig
{
private readonly TaskCompletionSource tcsInitialization = new();
private readonly TaskCompletionSource<GameConfigSection> tcsSystem = new();
private readonly TaskCompletionSource<GameConfigSection> tcsUiConfig = new();
private readonly TaskCompletionSource<GameConfigSection> tcsUiControl = new();
private readonly TaskCompletionSource tcsInitialization =
new(TaskCreationOptions.RunContinuationsAsynchronously);
private readonly TaskCompletionSource<GameConfigSection> tcsSystem =
new(TaskCreationOptions.RunContinuationsAsynchronously);
private readonly TaskCompletionSource<GameConfigSection> tcsUiConfig =
new(TaskCreationOptions.RunContinuationsAsynchronously);
private readonly TaskCompletionSource<GameConfigSection> tcsUiControl =
new(TaskCreationOptions.RunContinuationsAsynchronously);
private readonly GameConfigAddressResolver address = new();
private Hook<ConfigChangeDelegate>? configChangeHook;

View file

@ -139,7 +139,7 @@ internal sealed class Framework : IInternalDisposableService, IFramework
if (numTicks <= 0)
return Task.CompletedTask;
var tcs = new TaskCompletionSource();
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
this.tickDelayedTaskCompletionSources[tcs] = (this.tickCounter + (ulong)numTicks, cancellationToken);
return tcs.Task;
}

View file

@ -59,7 +59,7 @@ public sealed class SingleFontChooserDialog : IDisposable
private readonly int counter;
private readonly byte[] fontPreviewText = new byte[2048];
private readonly TaskCompletionSource<SingleFontSpec> tcs = new();
private readonly TaskCompletionSource<SingleFontSpec> tcs = new(TaskCreationOptions.RunContinuationsAsynchronously);
private readonly IFontAtlas atlas;
private string popupImGuiName;

View file

@ -336,7 +336,7 @@ internal class InterfaceManager : IInternalDisposableService
/// <returns>A <see cref="Task"/> that resolves once <paramref name="action"/> is run.</returns>
public Task RunBeforeImGuiRender(Action action)
{
var tcs = new TaskCompletionSource();
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
this.runBeforeImGuiRender.Enqueue(
() =>
{
@ -359,7 +359,7 @@ internal class InterfaceManager : IInternalDisposableService
/// <returns>A <see cref="Task"/> that resolves once <paramref name="func"/> is run.</returns>
public Task<T> RunBeforeImGuiRender<T>(Func<T> func)
{
var tcs = new TaskCompletionSource<T>();
var tcs = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
this.runBeforeImGuiRender.Enqueue(
() =>
{
@ -380,7 +380,7 @@ internal class InterfaceManager : IInternalDisposableService
/// <returns>A <see cref="Task"/> that resolves once <paramref name="action"/> is run.</returns>
public Task RunAfterImGuiRender(Action action)
{
var tcs = new TaskCompletionSource();
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
this.runAfterImGuiRender.Enqueue(
() =>
{
@ -403,7 +403,7 @@ internal class InterfaceManager : IInternalDisposableService
/// <returns>A <see cref="Task"/> that resolves once <paramref name="func"/> is run.</returns>
public Task<T> RunAfterImGuiRender<T>(Func<T> func)
{
var tcs = new TaskCompletionSource<T>();
var tcs = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
this.runAfterImGuiRender.Enqueue(
() =>
{

View file

@ -315,7 +315,7 @@ internal class PluginImageCache : IInternalDisposableService
private Task<T> RunInDownloadQueue<T>(Func<Task<T>> func, ulong requestedFrame)
{
var tcs = new TaskCompletionSource<T>();
var tcs = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
this.downloadQueue.Add(Tuple.Create(requestedFrame, async () =>
{
try
@ -332,7 +332,7 @@ internal class PluginImageCache : IInternalDisposableService
private Task<T> RunInLoadQueue<T>(Func<Task<T>> func)
{
var tcs = new TaskCompletionSource<T>();
var tcs = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
this.loadQueue.Add(async () =>
{
try

View file

@ -3774,7 +3774,7 @@ internal class PluginInstallerWindow : Window, IDisposable
this.errorModalMessage = message;
this.errorModalDrawing = true;
this.errorModalOnNextFrame = true;
this.errorModalTaskCompletionSource = new TaskCompletionSource();
this.errorModalTaskCompletionSource = new(TaskCreationOptions.RunContinuationsAsynchronously);
return this.errorModalTaskCompletionSource.Task;
}
@ -3782,7 +3782,7 @@ internal class PluginInstallerWindow : Window, IDisposable
{
this.updateModalOnNextFrame = true;
this.updateModalPlugin = plugin;
this.updateModalTaskCompletionSource = new TaskCompletionSource<bool>();
this.updateModalTaskCompletionSource = new(TaskCreationOptions.RunContinuationsAsynchronously);
return this.updateModalTaskCompletionSource.Task;
}

View file

@ -497,7 +497,7 @@ internal sealed partial class FontAtlasFactory
$"{nameof(FontAtlasAutoRebuildMode.Async)}.");
}
var tcs = new TaskCompletionSource<FontAtlasBuiltData>();
var tcs = new TaskCompletionSource<FontAtlasBuiltData>(TaskCreationOptions.RunContinuationsAsynchronously);
try
{
var rebuildIndex = Interlocked.Increment(ref this.buildIndex);

View file

@ -242,7 +242,7 @@ internal abstract class FontHandle : IFontHandle
if (this.Available)
return Task.FromResult<IFontHandle>(this);
var tcs = new TaskCompletionSource<IFontHandle>();
var tcs = new TaskCompletionSource<IFontHandle>(TaskCreationOptions.RunContinuationsAsynchronously);
this.ImFontChanged += OnImFontChanged;
this.Disposed += OnDisposed;
if (this.Available)

View file

@ -24,7 +24,8 @@ internal sealed class ViewportTextureWrap : IDalamudTextureWrap, IDeferredDispos
private readonly string? debugName;
private readonly LocalPlugin? ownerPlugin;
private readonly CancellationToken cancellationToken;
private readonly TaskCompletionSource<IDalamudTextureWrap> firstUpdateTaskCompletionSource = new();
private readonly TaskCompletionSource<IDalamudTextureWrap> firstUpdateTaskCompletionSource =
new(TaskCreationOptions.RunContinuationsAsynchronously);
private ImGuiViewportTextureArgs args;
private D3D11_TEXTURE2D_DESC desc;

View file

@ -59,7 +59,7 @@ internal sealed class DevTextureSaveMenu : IInternalDisposableService
{
var first = true;
var encoders = textureManager.Wic.GetSupportedEncoderInfos().ToList();
var tcs = new TaskCompletionSource<BitmapCodecInfo>();
var tcs = new TaskCompletionSource<BitmapCodecInfo>(TaskCreationOptions.RunContinuationsAsynchronously);
Service<InterfaceManager>.Get().Draw += DrawChoices;
encoder = await tcs.Task;
@ -108,7 +108,7 @@ internal sealed class DevTextureSaveMenu : IInternalDisposableService
string path;
{
var tcs = new TaskCompletionSource<string>();
var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
this.fileDialogManager.SaveFileDialog(
"Save texture...",
$"{encoder.Name.Replace(',', '.')}{{{string.Join(',', encoder.Extensions)}}}",

View file

@ -44,7 +44,9 @@ internal static class ServiceManager
private static readonly List<Type> LoadedServices = new();
#endif
private static readonly TaskCompletionSource BlockingServicesLoadedTaskCompletionSource = new();
private static readonly TaskCompletionSource BlockingServicesLoadedTaskCompletionSource =
new(TaskCreationOptions.RunContinuationsAsynchronously);
private static readonly CancellationTokenSource UnloadCancellationTokenSource = new();
private static ManualResetEvent unloadResetEvent = new(false);

View file

@ -332,7 +332,7 @@ internal static class Service<T> where T : IServiceType
break;
}
instanceTcs = new TaskCompletionSource<T>();
instanceTcs = new(TaskCreationOptions.RunContinuationsAsynchronously);
instanceTcs.SetException(new UnloadedException());
}

View file

@ -21,7 +21,7 @@ public static class AsyncUtils
/// <returns>Returns the first task that completes, according to <see cref="Task.IsCompletedSuccessfully"/>.</returns>
public static Task<T> FirstSuccessfulTask<T>(ICollection<Task<T>> tasks)
{
var tcs = new TaskCompletionSource<T>();
var tcs = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
var remainingTasks = tasks.Count;
foreach (var task in tasks)

View file

@ -238,7 +238,7 @@ internal class DynamicPriorityQueueLoader : IDisposable
params IDisposable?[] disposables)
: base(basis, cancellationToken, disposables)
{
this.taskCompletionSource = new();
this.taskCompletionSource = new(TaskCreationOptions.RunContinuationsAsynchronously);
this.immediateLoadFunction = immediateLoadFunction;
}