Browse Source

Added GC critical sections

pull/32/head
Anairkoen Schno 5 years ago
parent
commit
85057f5eab
1 changed files with 55 additions and 0 deletions
  1. +55
    -0
      IPA.Loader/Utilities/CriticalSection.cs

+ 55
- 0
IPA.Loader/Utilities/CriticalSection.cs View File

@ -52,6 +52,14 @@ namespace IPA.Utilities
private static volatile bool exitRecieved = false;
/// <summary>
/// Enters a critical execution section. Does not nest.
/// </summary>
/// <note>
/// 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.
/// </note>
public static void EnterExecuteSection()
{
ResetExitHandlers();
@ -60,6 +68,14 @@ namespace IPA.Utilities
_handler = sig => exitRecieved = true;
}
/// <summary>
/// Exits a critical execution section. Does not nest.
/// </summary>
/// <note>
/// 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.
/// </note>
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();
/// <summary>
/// Enters a GC critical section. Each call to this must be paired with a call to <see cref="ExitGCSection"/>.
/// </summary>
/// <note>
/// During a GC critical section, no GCs will occur.
///
/// This may throw an <see cref="EntryPointNotFoundException"/> if the build of Mono the game is running on does
/// not have `mono_unity_gc_disable` exported. Use with caution.
/// </note>
public static void EnterGCSection()
{
mono_unity_gc_disable();
}
/// <summary>
/// Exits a GC critical section. Each call to this must have a preceding call to <see cref="EnterGCSection"/>.
/// </summary>
/// <note>
/// During a GC critical section, no GCs will occur.
///
/// This may throw an <see cref="EntryPointNotFoundException"/> if the build of Mono the game is running on does
/// not have `mono_unity_gc_enable` exported. Use with caution.
/// </note>
public static void ExitGCSection()
{
mono_unity_gc_enable();
}
#endregion
}
}

Loading…
Cancel
Save