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`
feature/system-text-json
Meivyn 1 year 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 ConcurrentBag<Config> configs = new();
private static readonly AutoResetEvent configsChangedWatcher = new(false); private static readonly AutoResetEvent configsChangedWatcher = new(false);
public static readonly BlockingCollection<IConfigStore> RequiresSave = new();
private static readonly ConcurrentDictionary<DirectoryInfo, FileSystemWatcher> watchers private static readonly ConcurrentDictionary<DirectoryInfo, FileSystemWatcher> watchers
= new ConcurrentDictionary<DirectoryInfo, FileSystemWatcher>(new DirInfoEqComparer()); = new ConcurrentDictionary<DirectoryInfo, FileSystemWatcher>(new DirInfoEqComparer());
private static readonly ConcurrentDictionary<FileSystemWatcher, ConcurrentBag<Config>> watcherTrackConfigs private static readonly ConcurrentDictionary<FileSystemWatcher, ConcurrentBag<Config>> watcherTrackConfigs
= new ConcurrentDictionary<FileSystemWatcher, ConcurrentBag<Config>>(); = new ConcurrentDictionary<FileSystemWatcher, ConcurrentBag<Config>>();
private static BlockingCollection<IConfigStore> requiresSave = new();
private static SingleThreadTaskScheduler loadScheduler; private static SingleThreadTaskScheduler loadScheduler;
private static TaskFactory loadFactory; private static TaskFactory loadFactory;
private static Thread saveThread; private static Thread saveThread;
@ -62,6 +62,11 @@ namespace IPA.Config
AppDomain.CurrentDomain.ProcessExit += ShutdownRuntime; AppDomain.CurrentDomain.ProcessExit += ShutdownRuntime;
} }
internal static void AddRequiresSave(IConfigStore configStore)
{
requiresSave?.Add(configStore);
}
private static void ShutdownRuntime(object sender, EventArgs e) private static void ShutdownRuntime(object sender, EventArgs e)
=> ShutdownRuntime(); => ShutdownRuntime();
internal static void 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 saveThread.Abort(); // eww, but i don't like any of the other potential solutions
SaveAll(); SaveAll();
requiresSave.Dispose();
requiresSave = null;
} }
catch catch
{ {
@ -218,9 +226,14 @@ namespace IPA.Config
private static void SaveThread() private static void SaveThread()
{ {
if (requiresSave == null)
{
return;
}
try try
{ {
foreach (var item in RequiresSave.GetConsumingEnumerable())
foreach (var item in requiresSave.GetConsumingEnumerable())
{ {
try try
{ {
@ -242,10 +255,6 @@ namespace IPA.Config
{ {
// we got aborted :( // we got aborted :(
} }
finally
{
RequiresSave.Dispose();
}
} }
private static void LegacySaveThread() 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 static void ImplSignalChanged(IGeneratedStore s) => FindImpl(s)?.SignalChanged();
public void SignalChanged() public void SignalChanged()
{ {
ConfigRuntime.RequiresSave.Add(this);
ConfigRuntime.AddRequiresSave(this);
} }
internal static MethodInfo ImplInvokeChangedMethod = typeof(Impl).GetMethod(nameof(ImplInvokeChanged)); internal static MethodInfo ImplInvokeChangedMethod = typeof(Impl).GetMethod(nameof(ImplInvokeChanged));


Loading…
Cancel
Save