mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
Make all TCS RunContinuationsAsynchronously
This commit is contained in:
parent
856c198934
commit
1be5cd452d
14 changed files with 33 additions and 23 deletions
|
|
@ -16,10 +16,17 @@ namespace Dalamud.Game.Config;
|
||||||
[ServiceManager.EarlyLoadedService]
|
[ServiceManager.EarlyLoadedService]
|
||||||
internal sealed class GameConfig : IInternalDisposableService, IGameConfig
|
internal sealed class GameConfig : IInternalDisposableService, IGameConfig
|
||||||
{
|
{
|
||||||
private readonly TaskCompletionSource tcsInitialization = new();
|
private readonly TaskCompletionSource tcsInitialization =
|
||||||
private readonly TaskCompletionSource<GameConfigSection> tcsSystem = new();
|
new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
private readonly TaskCompletionSource<GameConfigSection> tcsUiConfig = new();
|
|
||||||
private readonly TaskCompletionSource<GameConfigSection> tcsUiControl = new();
|
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 readonly GameConfigAddressResolver address = new();
|
||||||
private Hook<ConfigChangeDelegate>? configChangeHook;
|
private Hook<ConfigChangeDelegate>? configChangeHook;
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ internal sealed class Framework : IInternalDisposableService, IFramework
|
||||||
if (numTicks <= 0)
|
if (numTicks <= 0)
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
|
||||||
var tcs = new TaskCompletionSource();
|
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
this.tickDelayedTaskCompletionSources[tcs] = (this.tickCounter + (ulong)numTicks, cancellationToken);
|
this.tickDelayedTaskCompletionSources[tcs] = (this.tickCounter + (ulong)numTicks, cancellationToken);
|
||||||
return tcs.Task;
|
return tcs.Task;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ public sealed class SingleFontChooserDialog : IDisposable
|
||||||
|
|
||||||
private readonly int counter;
|
private readonly int counter;
|
||||||
private readonly byte[] fontPreviewText = new byte[2048];
|
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 readonly IFontAtlas atlas;
|
||||||
|
|
||||||
private string popupImGuiName;
|
private string popupImGuiName;
|
||||||
|
|
|
||||||
|
|
@ -336,7 +336,7 @@ internal class InterfaceManager : IInternalDisposableService
|
||||||
/// <returns>A <see cref="Task"/> that resolves once <paramref name="action"/> is run.</returns>
|
/// <returns>A <see cref="Task"/> that resolves once <paramref name="action"/> is run.</returns>
|
||||||
public Task RunBeforeImGuiRender(Action action)
|
public Task RunBeforeImGuiRender(Action action)
|
||||||
{
|
{
|
||||||
var tcs = new TaskCompletionSource();
|
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
this.runBeforeImGuiRender.Enqueue(
|
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>
|
/// <returns>A <see cref="Task"/> that resolves once <paramref name="func"/> is run.</returns>
|
||||||
public Task<T> RunBeforeImGuiRender<T>(Func<T> func)
|
public Task<T> RunBeforeImGuiRender<T>(Func<T> func)
|
||||||
{
|
{
|
||||||
var tcs = new TaskCompletionSource<T>();
|
var tcs = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
this.runBeforeImGuiRender.Enqueue(
|
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>
|
/// <returns>A <see cref="Task"/> that resolves once <paramref name="action"/> is run.</returns>
|
||||||
public Task RunAfterImGuiRender(Action action)
|
public Task RunAfterImGuiRender(Action action)
|
||||||
{
|
{
|
||||||
var tcs = new TaskCompletionSource();
|
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
this.runAfterImGuiRender.Enqueue(
|
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>
|
/// <returns>A <see cref="Task"/> that resolves once <paramref name="func"/> is run.</returns>
|
||||||
public Task<T> RunAfterImGuiRender<T>(Func<T> func)
|
public Task<T> RunAfterImGuiRender<T>(Func<T> func)
|
||||||
{
|
{
|
||||||
var tcs = new TaskCompletionSource<T>();
|
var tcs = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
this.runAfterImGuiRender.Enqueue(
|
this.runAfterImGuiRender.Enqueue(
|
||||||
() =>
|
() =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -315,7 +315,7 @@ internal class PluginImageCache : IInternalDisposableService
|
||||||
|
|
||||||
private Task<T> RunInDownloadQueue<T>(Func<Task<T>> func, ulong requestedFrame)
|
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 () =>
|
this.downloadQueue.Add(Tuple.Create(requestedFrame, async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -332,7 +332,7 @@ internal class PluginImageCache : IInternalDisposableService
|
||||||
|
|
||||||
private Task<T> RunInLoadQueue<T>(Func<Task<T>> func)
|
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 () =>
|
this.loadQueue.Add(async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
||||||
|
|
@ -3774,7 +3774,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
this.errorModalMessage = message;
|
this.errorModalMessage = message;
|
||||||
this.errorModalDrawing = true;
|
this.errorModalDrawing = true;
|
||||||
this.errorModalOnNextFrame = true;
|
this.errorModalOnNextFrame = true;
|
||||||
this.errorModalTaskCompletionSource = new TaskCompletionSource();
|
this.errorModalTaskCompletionSource = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
return this.errorModalTaskCompletionSource.Task;
|
return this.errorModalTaskCompletionSource.Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3782,7 +3782,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
{
|
{
|
||||||
this.updateModalOnNextFrame = true;
|
this.updateModalOnNextFrame = true;
|
||||||
this.updateModalPlugin = plugin;
|
this.updateModalPlugin = plugin;
|
||||||
this.updateModalTaskCompletionSource = new TaskCompletionSource<bool>();
|
this.updateModalTaskCompletionSource = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
return this.updateModalTaskCompletionSource.Task;
|
return this.updateModalTaskCompletionSource.Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -497,7 +497,7 @@ internal sealed partial class FontAtlasFactory
|
||||||
$"{nameof(FontAtlasAutoRebuildMode.Async)}.");
|
$"{nameof(FontAtlasAutoRebuildMode.Async)}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var tcs = new TaskCompletionSource<FontAtlasBuiltData>();
|
var tcs = new TaskCompletionSource<FontAtlasBuiltData>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var rebuildIndex = Interlocked.Increment(ref this.buildIndex);
|
var rebuildIndex = Interlocked.Increment(ref this.buildIndex);
|
||||||
|
|
|
||||||
|
|
@ -242,7 +242,7 @@ internal abstract class FontHandle : IFontHandle
|
||||||
if (this.Available)
|
if (this.Available)
|
||||||
return Task.FromResult<IFontHandle>(this);
|
return Task.FromResult<IFontHandle>(this);
|
||||||
|
|
||||||
var tcs = new TaskCompletionSource<IFontHandle>();
|
var tcs = new TaskCompletionSource<IFontHandle>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
this.ImFontChanged += OnImFontChanged;
|
this.ImFontChanged += OnImFontChanged;
|
||||||
this.Disposed += OnDisposed;
|
this.Disposed += OnDisposed;
|
||||||
if (this.Available)
|
if (this.Available)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ internal sealed class ViewportTextureWrap : IDalamudTextureWrap, IDeferredDispos
|
||||||
private readonly string? debugName;
|
private readonly string? debugName;
|
||||||
private readonly LocalPlugin? ownerPlugin;
|
private readonly LocalPlugin? ownerPlugin;
|
||||||
private readonly CancellationToken cancellationToken;
|
private readonly CancellationToken cancellationToken;
|
||||||
private readonly TaskCompletionSource<IDalamudTextureWrap> firstUpdateTaskCompletionSource = new();
|
private readonly TaskCompletionSource<IDalamudTextureWrap> firstUpdateTaskCompletionSource =
|
||||||
|
new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
|
|
||||||
private ImGuiViewportTextureArgs args;
|
private ImGuiViewportTextureArgs args;
|
||||||
private D3D11_TEXTURE2D_DESC desc;
|
private D3D11_TEXTURE2D_DESC desc;
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ internal sealed class DevTextureSaveMenu : IInternalDisposableService
|
||||||
{
|
{
|
||||||
var first = true;
|
var first = true;
|
||||||
var encoders = textureManager.Wic.GetSupportedEncoderInfos().ToList();
|
var encoders = textureManager.Wic.GetSupportedEncoderInfos().ToList();
|
||||||
var tcs = new TaskCompletionSource<BitmapCodecInfo>();
|
var tcs = new TaskCompletionSource<BitmapCodecInfo>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
Service<InterfaceManager>.Get().Draw += DrawChoices;
|
Service<InterfaceManager>.Get().Draw += DrawChoices;
|
||||||
|
|
||||||
encoder = await tcs.Task;
|
encoder = await tcs.Task;
|
||||||
|
|
@ -108,7 +108,7 @@ internal sealed class DevTextureSaveMenu : IInternalDisposableService
|
||||||
|
|
||||||
string path;
|
string path;
|
||||||
{
|
{
|
||||||
var tcs = new TaskCompletionSource<string>();
|
var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
this.fileDialogManager.SaveFileDialog(
|
this.fileDialogManager.SaveFileDialog(
|
||||||
"Save texture...",
|
"Save texture...",
|
||||||
$"{encoder.Name.Replace(',', '.')}{{{string.Join(',', encoder.Extensions)}}}",
|
$"{encoder.Name.Replace(',', '.')}{{{string.Join(',', encoder.Extensions)}}}",
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,9 @@ internal static class ServiceManager
|
||||||
private static readonly List<Type> LoadedServices = new();
|
private static readonly List<Type> LoadedServices = new();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private static readonly TaskCompletionSource BlockingServicesLoadedTaskCompletionSource = new();
|
private static readonly TaskCompletionSource BlockingServicesLoadedTaskCompletionSource =
|
||||||
|
new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
|
|
||||||
private static readonly CancellationTokenSource UnloadCancellationTokenSource = new();
|
private static readonly CancellationTokenSource UnloadCancellationTokenSource = new();
|
||||||
|
|
||||||
private static ManualResetEvent unloadResetEvent = new(false);
|
private static ManualResetEvent unloadResetEvent = new(false);
|
||||||
|
|
|
||||||
|
|
@ -332,7 +332,7 @@ internal static class Service<T> where T : IServiceType
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
instanceTcs = new TaskCompletionSource<T>();
|
instanceTcs = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
instanceTcs.SetException(new UnloadedException());
|
instanceTcs.SetException(new UnloadedException());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ public static class AsyncUtils
|
||||||
/// <returns>Returns the first task that completes, according to <see cref="Task.IsCompletedSuccessfully"/>.</returns>
|
/// <returns>Returns the first task that completes, according to <see cref="Task.IsCompletedSuccessfully"/>.</returns>
|
||||||
public static Task<T> FirstSuccessfulTask<T>(ICollection<Task<T>> tasks)
|
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;
|
var remainingTasks = tasks.Count;
|
||||||
|
|
||||||
foreach (var task in tasks)
|
foreach (var task in tasks)
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,7 @@ internal class DynamicPriorityQueueLoader : IDisposable
|
||||||
params IDisposable?[] disposables)
|
params IDisposable?[] disposables)
|
||||||
: base(basis, cancellationToken, disposables)
|
: base(basis, cancellationToken, disposables)
|
||||||
{
|
{
|
||||||
this.taskCompletionSource = new();
|
this.taskCompletionSource = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
this.immediateLoadFunction = immediateLoadFunction;
|
this.immediateLoadFunction = immediateLoadFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue