Browse Source

Merge pull request #104 from nicoco007/fix-exception-when-changed-called-in-zenject-dispose

Fix exception when `Changed` is called in Zenject-invoked `Dispose`
master
Meivyn 3 months ago
committed by GitHub
parent
commit
777adc0222
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions
  1. +15
    -6
      IPA.Loader/Config/ConfigRuntime.cs
  2. +1
    -1
      IPA.Loader/Config/Stores/GeneratedStoreImpl/IGeneratedStore.cs

+ 15
- 6
IPA.Loader/Config/ConfigRuntime.cs View File

@ -27,11 +27,11 @@ namespace IPA.Config
private static readonly ConcurrentBag<Config> configs = new();
private static readonly AutoResetEvent configsChangedWatcher = new(false);
public static readonly BlockingCollection<IConfigStore> RequiresSave = new();
private static readonly ConcurrentDictionary<DirectoryInfo, FileSystemWatcher> watchers
= new ConcurrentDictionary<DirectoryInfo, FileSystemWatcher>(new DirInfoEqComparer());
private static readonly ConcurrentDictionary<FileSystemWatcher, ConcurrentBag<Config>> watcherTrackConfigs
= new ConcurrentDictionary<FileSystemWatcher, ConcurrentBag<Config>>();
private static BlockingCollection<IConfigStore> requiresSave = new();
private static SingleThreadTaskScheduler loadScheduler;
private static TaskFactory loadFactory;
private static Thread saveThread;
@ -62,6 +62,11 @@ namespace IPA.Config
AppDomain.CurrentDomain.ProcessExit += ShutdownRuntime;
}
internal static void AddRequiresSave(IConfigStore configStore)
{
requiresSave?.Add(configStore);
}
private static void ShutdownRuntime(object sender, EventArgs e)
=> ShutdownRuntime();
internal static void ShutdownRuntime()
@ -79,6 +84,9 @@ namespace IPA.Config
saveThread.Abort(); // eww, but i don't like any of the other potential solutions
SaveAll();
requiresSave.Dispose();
requiresSave = null;
}
catch
{
@ -218,9 +226,14 @@ namespace IPA.Config
private static void SaveThread()
{
if (requiresSave == null)
{
return;
}
try
{
foreach (var item in RequiresSave.GetConsumingEnumerable())
foreach (var item in requiresSave.GetConsumingEnumerable())
{
try
{
@ -242,10 +255,6 @@ namespace IPA.Config
{
// we got aborted :(
}
finally
{
RequiresSave.Dispose();
}
}
private static void LegacySaveThread()


+ 1
- 1
IPA.Loader/Config/Stores/GeneratedStoreImpl/IGeneratedStore.cs View File

@ -59,7 +59,7 @@ namespace IPA.Config.Stores
public static void ImplSignalChanged(IGeneratedStore s) => FindImpl(s)?.SignalChanged();
public void SignalChanged()
{
ConfigRuntime.RequiresSave.Add(this);
ConfigRuntime.AddRequiresSave(this);
}
internal static MethodInfo ImplInvokeChangedMethod = typeof(Impl).GetMethod(nameof(ImplInvokeChanged));


Loading…
Cancel
Save