Skip to content

Commit ab60d34

Browse files
authored
Merge pull request #5 from js6pak/spinlock-mono-compat
Fix net35 build's forward compatiblity with Unity 2018-2020 mono
2 parents 171c409 + 6a573cd commit ab60d34

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/MonoMod.Backports/System/Threading/SpinLock,lt_fx_4.0.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
1212

1313
using System.Diagnostics;
14+
using System.Reflection;
1415
using System.Runtime.CompilerServices;
1516

1617
namespace System.Threading
@@ -402,6 +403,11 @@ private void DecrementWaiters()
402403
}
403404
}
404405

406+
private static readonly ConstructorInfo LockRecursionExceptionConstructor =
407+
(Type.GetType("System.Threading.LockRecursionException, System.Core", false)
408+
?? Type.GetType("System.Threading.LockRecursionException")!)
409+
.GetConstructor([typeof(string)])!;
410+
405411
/// <summary>
406412
/// ContinueTryEnter for the thread tracking mode enabled
407413
/// </summary>
@@ -416,7 +422,10 @@ private void ContinueTryEnterWithThreadTracking(int millisecondsTimeout, uint st
416422
if (_owner == newOwner)
417423
{
418424
// We don't allow lock recursion.
419-
throw new LockRecursionException("Recursive lock enter");
425+
426+
// Unity 2018-2020 mono is missing a type forward for LockRecursionException inside of System.Core.dll
427+
// To maintain forward compatibility try looking for it in mscorlib using reflection
428+
throw (Exception)LockRecursionExceptionConstructor.Invoke(["Recursive lock enter"]);
420429
}
421430

422431
SpinWait spinner = default;

0 commit comments

Comments
 (0)