Imported Upstream version 5.8.0.22

Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-10-19 20:04:20 +00:00
parent 5f4a27cc8a
commit 7d05485754
5020 changed files with 114082 additions and 186061 deletions

View File

@ -49,6 +49,9 @@ namespace System.Threading
static int WaitMultiple(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext, bool WaitAll)
{
if (waitHandles.Length > MaxWaitHandles)
return WAIT_FAILED;
int release_last = -1;
try {
@ -58,8 +61,7 @@ namespace System.Threading
#endif
for (int i = 0; i < waitHandles.Length; ++i) {
try {
} finally {
try {} finally {
/* we have to put it in a finally block, to avoid having a ThreadAbortException
* between the return from DangerousAddRef and the assignement to release_last */
bool release = false;
@ -68,10 +70,14 @@ namespace System.Threading
}
}
if (WaitAll)
return WaitAll_internal (waitHandles, millisecondsTimeout);
else
return WaitAny_internal (waitHandles, millisecondsTimeout);
unsafe {
IntPtr* handles = stackalloc IntPtr[waitHandles.Length];
for (int i = 0; i < waitHandles.Length; ++i)
handles[i] = waitHandles[i].SafeWaitHandle.DangerousGetHandle ();
return Wait_internal(handles, waitHandles.Length, WaitAll, millisecondsTimeout);
}
} finally {
for (int i = release_last; i >= 0; --i) {
waitHandles [i].SafeWaitHandle.DangerousRelease ();
@ -84,12 +90,6 @@ namespace System.Threading
}
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern int WaitAll_internal(WaitHandle[] handles, int ms);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern int WaitAny_internal(WaitHandle[] handles, int ms);
static int WaitOneNative (SafeHandle waitableSafeHandle, uint millisecondsTimeout, bool hasThreadAffinity, bool exitContext)
{
bool release = false;
@ -101,7 +101,10 @@ namespace System.Threading
waitableSafeHandle.DangerousAddRef (ref release);
return WaitOne_internal (waitableSafeHandle.DangerousGetHandle (), (int) millisecondsTimeout);
unsafe {
IntPtr handle = waitableSafeHandle.DangerousGetHandle();
return Wait_internal(&handle, 1, false, (int)millisecondsTimeout);
}
} finally {
if (release)
waitableSafeHandle.DangerousRelease ();
@ -114,7 +117,7 @@ namespace System.Threading
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
static extern int WaitOne_internal(IntPtr handle, int ms);
unsafe static extern int Wait_internal(IntPtr* handles, int numHandles, bool waitAll, int ms);
static int SignalAndWaitOne (SafeWaitHandle waitHandleToSignal,SafeWaitHandle waitHandleToWaitOn, int millisecondsTimeout, bool hasThreadAffinity, bool exitContext)
{