Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Move WaitHandle to shared CoreLib (dotnet/coreclr#22634)
Browse files Browse the repository at this point in the history
* Move part of WaitHandle to shared CoreLib

* Bring back OpenExistingResult to fix build

* Move reminder of WaitHandle to shared, implement SynchronizationContext logic in managed code, handle SafeHandle referencing in managed code

* Update with changes neeeded for CoreRT

* Span -> ReadOnlySpan

* Remove dead code

* Fix SafeHandle error handling

* Avoid double check on input values in WaitHandle.WaitOne overloads

* Make OpenExistingResult private protected instead of internal

* Make WaitHandle._waitHandle private

* Code style fixes

* Remove unnecessary GC.KeepAlive

* Move ERROR_TOO_MANY_POSTS exception handling to CoreCLR specific code

* Add cache for wait arrays to match previous CoreRT behavior and reduce GC pressure, change unmanaged code to allocate small array on stack

* Address PR feedback

* Reduce allocations/copying by moving stack allocation to managed code

* Address PR feedback

* Minor code reshuffle

* Move thread local access close to each other

* Address code style feedback

* Add const to Wait* constants

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
  • Loading branch information
filipnavara authored and jkotas committed Feb 25, 2019
1 parent 8dd8fa3 commit 572a154
Show file tree
Hide file tree
Showing 4 changed files with 441 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Timeout.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\TimeoutHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Timer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\WaitHandle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\WaitHandleCannotBeOpenedException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ThreadStaticAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ThrowHelper.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ private static OpenExistingResult OpenExistingWorker(string name, out EventWaitH

public bool Reset()
{
bool res = Interop.Kernel32.ResetEvent(_waitHandle);
bool res = Interop.Kernel32.ResetEvent(SafeWaitHandle);
if (!res)
throw Win32Marshal.GetExceptionForLastWin32Error();
return res;
}

public bool Set()
{
bool res = Interop.Kernel32.SetEvent(_waitHandle);
bool res = Interop.Kernel32.SetEvent(SafeWaitHandle);
if (!res)
throw Win32Marshal.GetExceptionForLastWin32Error();
return res;
Expand Down
2 changes: 1 addition & 1 deletion src/Common/src/CoreLib/System/Threading/Mutex.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static OpenExistingResult OpenExistingWorker(string name, out Mutex resu
// in a Mutex's ACL is MUTEX_ALL_ACCESS (0x1F0001).
public void ReleaseMutex()
{
if (!Interop.Kernel32.ReleaseMutex(_waitHandle))
if (!Interop.Kernel32.ReleaseMutex(SafeWaitHandle))
{
throw new ApplicationException(SR.Arg_SynchronizationLockException);
}
Expand Down
Loading

0 comments on commit 572a154

Please sign in to comment.