diff --git a/src/Shared/Internal/ReEntrantScopeLock.cs b/src/Shared/Internal/ReEntrantScopeLock.cs index 3ba1db13..67bf30c7 100644 --- a/src/Shared/Internal/ReEntrantScopeLock.cs +++ b/src/Shared/Internal/ReEntrantScopeLock.cs @@ -43,13 +43,13 @@ private static bool TryGetLock(HttpContextBase context) } // If already locked, return false - if (IsLocked(context)) + if (context.Items?.Contains(ReEntrantLock) == true) { return false; } // Get the lock - Lock(context); + context.Items[ReEntrantLock] = bool.TrueString; // Indicate the lock was successfully acquired return true; @@ -60,24 +60,9 @@ public void Dispose() // Only unlock if we were the ones who locked it if (IsLockAcquired) { - Unlock(_httpContext); + _httpContext.Items?.Remove(ReEntrantLock); } } - - private static bool IsLocked(HttpContextBase context) - { - return context.Items?.Contains(ReEntrantLock) == true; - } - - private static void Lock(HttpContextBase context) - { - context.Items[ReEntrantLock] = bool.TrueString; - } - - private static void Unlock(HttpContextBase context) - { - context.Items?.Remove(ReEntrantLock); - } #else private static readonly AsyncLocal ReEntrantLock = new AsyncLocal(); @@ -90,13 +75,13 @@ private static bool TryGetLock(HttpContextBase context) } // If already locked, return false - if (IsLocked()) + if (ReEntrantLock.Value) { return false; } // Get the lock - Lock(); + ReEntrantLock.Value = true; // Indicate the lock was successfully acquired return true; @@ -107,24 +92,9 @@ public void Dispose() // Only unlock if we were the ones who locked it if (IsLockAcquired) { - Unlock(); + ReEntrantLock.Value = false; } } - - private static bool IsLocked() - { - return ReEntrantLock.Value; - } - - private static void Lock() - { - ReEntrantLock.Value = true; - } - - private static void Unlock() - { - ReEntrantLock.Value = false; - } #endif } }