mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 14:23:40 +01:00
Fix async plugin load and show full profiler (#898)
This commit is contained in:
parent
86b5eec493
commit
c7dc8c81f4
20 changed files with 404 additions and 248 deletions
|
|
@ -23,9 +23,6 @@ namespace Dalamud
|
|||
// ReSharper disable once StaticMemberInGenericType
|
||||
private static readonly TaskCompletionSource<T> InstanceTcs = new();
|
||||
|
||||
// ReSharper disable once StaticMemberInGenericType
|
||||
private static bool startLoaderInvoked = false;
|
||||
|
||||
static Service()
|
||||
{
|
||||
var exposeToPlugins = typeof(T).GetCustomAttribute<PluginInterfaceAttribute>() != null;
|
||||
|
|
@ -45,37 +42,29 @@ namespace Dalamud
|
|||
[UsedImplicitly]
|
||||
public static Task<T> StartLoader()
|
||||
{
|
||||
if (startLoaderInvoked)
|
||||
throw new InvalidOperationException("StartLoader has already been called.");
|
||||
|
||||
var attr = typeof(T).GetCustomAttribute<ServiceManager.Service>(true)?.GetType();
|
||||
if (attr?.IsAssignableTo(typeof(ServiceManager.EarlyLoadedService)) != true)
|
||||
throw new InvalidOperationException($"{typeof(T).Name} is not an EarlyLoadedService");
|
||||
|
||||
startLoaderInvoked = true;
|
||||
return Task.Run(async () =>
|
||||
return Task.Run(Timings.AttachTimingHandle(async () =>
|
||||
{
|
||||
using (Timings.Start($"{typeof(T).Namespace} Enable"))
|
||||
ServiceManager.Log.Debug("Service<{0}>: Begin construction", typeof(T).Name);
|
||||
try
|
||||
{
|
||||
var x = await ConstructObject();
|
||||
if (attr?.IsAssignableTo(typeof(ServiceManager.BlockingEarlyLoadedService)) == true)
|
||||
ServiceManager.Log.Debug("Service<{0}>: Begin construction", typeof(T).Name);
|
||||
try
|
||||
{
|
||||
var x = await ConstructObject();
|
||||
if (attr?.IsAssignableTo(typeof(ServiceManager.BlockingEarlyLoadedService)) == true)
|
||||
ServiceManager.Log.Debug("Service<{0}>: Construction complete", typeof(T).Name);
|
||||
InstanceTcs.SetResult(x);
|
||||
return x;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
InstanceTcs.SetException(e);
|
||||
if (attr?.IsAssignableTo(typeof(ServiceManager.BlockingEarlyLoadedService)) == true)
|
||||
ServiceManager.Log.Error(e, "Service<{0}>: Construction failure", typeof(T).Name);
|
||||
throw;
|
||||
}
|
||||
ServiceManager.Log.Debug("Service<{0}>: Construction complete", typeof(T).Name);
|
||||
InstanceTcs.SetResult(x);
|
||||
return x;
|
||||
}
|
||||
});
|
||||
catch (Exception e)
|
||||
{
|
||||
InstanceTcs.SetException(e);
|
||||
if (attr?.IsAssignableTo(typeof(ServiceManager.BlockingEarlyLoadedService)) == true)
|
||||
ServiceManager.Log.Error(e, "Service<{0}>: Construction failure", typeof(T).Name);
|
||||
throw;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -165,7 +154,10 @@ namespace Dalamud
|
|||
var ctor = GetServiceConstructor();
|
||||
var args = await Task.WhenAll(
|
||||
ctor.GetParameters().Select(x => GetServiceObjectConstructArgument(x.ParameterType)));
|
||||
return (T)ctor.Invoke(args)!;
|
||||
using (Timings.Start($"{typeof(T).Name} Construct"))
|
||||
{
|
||||
return (T)ctor.Invoke(args)!;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue