diff --git a/IPA.Loader/Utilities/CriticalSection.cs b/IPA.Loader/Utilities/CriticalSection.cs index cdbb982e..f2205afa 100644 --- a/IPA.Loader/Utilities/CriticalSection.cs +++ b/IPA.Loader/Utilities/CriticalSection.cs @@ -52,6 +52,14 @@ namespace IPA.Utilities private static volatile bool exitRecieved = false; + /// + /// Enters a critical execution section. Does not nest. + /// + /// + /// During a critical execution section, the program must execute until the end of the section before + /// exiting. If an exit signal is recieved during the section, it will be canceled, and the process + /// will terminate at the end of the section. + /// public static void EnterExecuteSection() { ResetExitHandlers(); @@ -60,6 +68,14 @@ namespace IPA.Utilities _handler = sig => exitRecieved = true; } + /// + /// Exits a critical execution section. Does not nest. + /// + /// + /// During a critical execution section, the program must execute until the end of the section before + /// exiting. If an exit signal is recieved during the section, it will be canceled, and the process + /// will terminate at the end of the section. + /// public static void ExitExecuteSection() { _handler = null; @@ -70,5 +86,44 @@ namespace IPA.Utilities #endregion + #region GC section + + // i wish i could reference GC_enable and GC_disable directly + [DllImport("mono-2.0-bdwgc")] + private static extern void mono_unity_gc_enable(); + [DllImport("mono-2.0-bdwgc")] + private static extern void mono_unity_gc_disable(); + + /// + /// Enters a GC critical section. Each call to this must be paired with a call to . + /// + /// + /// During a GC critical section, no GCs will occur. + /// + /// This may throw an if the build of Mono the game is running on does + /// not have `mono_unity_gc_disable` exported. Use with caution. + /// + public static void EnterGCSection() + { + mono_unity_gc_disable(); + } + + + /// + /// Exits a GC critical section. Each call to this must have a preceding call to . + /// + /// + /// During a GC critical section, no GCs will occur. + /// + /// This may throw an if the build of Mono the game is running on does + /// not have `mono_unity_gc_enable` exported. Use with caution. + /// + public static void ExitGCSection() + { + mono_unity_gc_enable(); + } + + #endregion + } }