From 7ffd40ddcc98bf9791c57591600a8fe077ee5b92 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Wed, 4 Dec 2019 19:40:41 -0600 Subject: [PATCH] Added some conditional code for .NET 3 for the sync helpers --- IPA.Loader/Utilities/Synchronization.cs | 15 +++++++++++---- Net3-Proxy/Extensions.cs | 8 ++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/IPA.Loader/Utilities/Synchronization.cs b/IPA.Loader/Utilities/Synchronization.cs index d110b78c..40224997 100644 --- a/IPA.Loader/Utilities/Synchronization.cs +++ b/IPA.Loader/Utilities/Synchronization.cs @@ -4,6 +4,9 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +#if NET3 +using Net3_Proxy; +#endif namespace IPA.Utilities { @@ -22,7 +25,7 @@ namespace IPA.Utilities /// public static class Synchronization { - #region Locker structs +#region Locker structs /// /// A locker for a that automatically releases when it is disposed. /// Create this with . @@ -80,6 +83,7 @@ namespace IPA.Utilities void IDisposable.Dispose() => sem.Release(); } +#if NET4 /// /// A locker for a that was created asynchronously and automatically releases /// when it is disposed. Create this with . @@ -95,6 +99,7 @@ namespace IPA.Utilities void IDisposable.Dispose() => sem.Release(); } +#endif /// /// A locker for a write lock on a that automatically releases when @@ -160,9 +165,9 @@ namespace IPA.Utilities void IDisposable.Dispose() => rwl.ExitUpgradeableReadLock(); } - #endregion +#endregion - #region Accessors +#region Accessors // TODO: add async fun stuff to this /// @@ -186,6 +191,7 @@ namespace IPA.Utilities /// the locker to use with public static SemaphoreSlimLocker Lock(SemaphoreSlim sem) => new SemaphoreSlimLocker(sem); +#if NET4 // TODO: make this work on NET3 too /// /// Creates a locker for a slim semaphore asynchronously. /// @@ -197,6 +203,7 @@ namespace IPA.Utilities await locker.Lock(); return locker; } +#endif /// /// Creates a locker for a write lock . @@ -218,6 +225,6 @@ namespace IPA.Utilities /// the lock to acquire in upgradable read mode /// the locker to use with public static ReaderWriterLockSlimUpgradableReadLocker LockReadUpgradable(ReaderWriterLockSlim rwl) => new ReaderWriterLockSlimUpgradableReadLocker(rwl); - #endregion +#endregion } } diff --git a/Net3-Proxy/Extensions.cs b/Net3-Proxy/Extensions.cs index ac1cc0bf..9dfd6653 100644 --- a/Net3-Proxy/Extensions.cs +++ b/Net3-Proxy/Extensions.cs @@ -171,4 +171,12 @@ namespace Net3_Proxy new object()); } + + public static class SemaphoreSlimExtesnions + { // TODO: finish the WaitAsync members + /*public static Task WaitAsync(this SemaphoreSlim self) + { + return null; + }*/ + } }