mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
remove: SafeCriticalSection - remove TryEnter method
This commit is contained in:
committed by
Chris Cameron
parent
84b5b636f6
commit
033008616f
@@ -37,30 +37,5 @@ namespace ICD.Common.Utils.Tests
|
||||
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryEnterTest()
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
SafeCriticalSection section = new SafeCriticalSection();
|
||||
section.Enter();
|
||||
|
||||
// ReSharper disable once NotAccessedVariable
|
||||
ThreadingUtils.SafeInvoke(() => { result = section.TryEnter() ? 0 : 1; });
|
||||
|
||||
Assert.IsTrue(ThreadingUtils.Wait(() => result == 1, 1000));
|
||||
|
||||
section.Leave();
|
||||
|
||||
// ReSharper disable once RedundantAssignment
|
||||
ThreadingUtils.SafeInvoke(() =>
|
||||
{
|
||||
result = section.TryEnter() ? 2 : 0;
|
||||
section.Leave();
|
||||
});
|
||||
|
||||
Assert.IsTrue(ThreadingUtils.Wait(() => result == 2, 1000));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,31 +90,6 @@ namespace ICD.Common.Utils
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to enter the critical section without blocking.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// True, calling thread has ownership of the critical section; otherwise, false.
|
||||
/// </returns>
|
||||
public bool TryEnter()
|
||||
{
|
||||
if (m_CriticalSection == null)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
#if DEBUG
|
||||
return m_CriticalSection.WaitForMutex(0);
|
||||
#else
|
||||
return m_CriticalSection.TryEnter();
|
||||
#endif
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,17 +24,6 @@ namespace ICD.Common.Utils
|
||||
Monitor.Exit(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to enter the critical section without blocking.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// True, calling thread has ownership of the critical section; otherwise, false.
|
||||
/// </returns>
|
||||
public bool TryEnter()
|
||||
{
|
||||
return Monitor.TryEnter(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user