1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
/*============================================================
**
** COMWaitHandle.cpp
**
** Purpose: Native methods on System.WaitHandle
**
**
===========================================================*/
#include "common.h"
#include "object.h"
#include "field.h"
#include "excep.h"
#include "comwaithandle.h"
FCIMPL2(INT32, WaitHandleNative::CorWaitOneNative, HANDLE handle, INT32 timeout)
{
FCALL_CONTRACT;
INT32 retVal = 0;
HELPER_METHOD_FRAME_BEGIN_RET_0();
_ASSERTE(handle != 0);
_ASSERTE(handle != INVALID_HANDLE_VALUE);
Thread* pThread = GET_THREAD();
retVal = pThread->DoAppropriateWait(1, &handle, TRUE, timeout, (WaitMode)(WaitMode_Alertable | WaitMode_IgnoreSyncCtx));
HELPER_METHOD_FRAME_END();
return retVal;
}
FCIMPLEND
FCIMPL4(INT32, WaitHandleNative::CorWaitMultipleNative, HANDLE *handleArray, INT32 numHandles, CLR_BOOL waitForAll, INT32 timeout)
{
FCALL_CONTRACT;
INT32 ret = 0;
HELPER_METHOD_FRAME_BEGIN_RET_0();
Thread * pThread = GET_THREAD();
#ifdef FEATURE_COMINTEROP_APARTMENT_SUPPORT
// There are some issues with wait-all from an STA thread
// - https://github.com/dotnet/coreclr/issues/17787#issuecomment-385117537
if (waitForAll && numHandles > 1 && pThread->GetApartment() == Thread::AS_InSTA)
{
COMPlusThrow(kNotSupportedException, W("NotSupported_WaitAllSTAThread"));
}
#endif // FEATURE_COMINTEROP_APARTMENT_SUPPORT
ret = pThread->DoAppropriateWait(numHandles, handleArray, waitForAll, timeout, (WaitMode)(WaitMode_Alertable | WaitMode_IgnoreSyncCtx));
HELPER_METHOD_FRAME_END();
return ret;
}
FCIMPLEND
FCIMPL3(INT32, WaitHandleNative::CorSignalAndWaitOneNative, HANDLE waitHandleSignalUNSAFE, HANDLE waitHandleWaitUNSAFE, INT32 timeout)
{
FCALL_CONTRACT;
INT32 retVal = 0;
HELPER_METHOD_FRAME_BEGIN_RET_0();
_ASSERTE(waitHandleSignalUNSAFE != 0);
_ASSERTE(waitHandleWaitUNSAFE != 0);
Thread* pThread = GET_THREAD();
#ifdef FEATURE_COMINTEROP
if (pThread->GetApartment() == Thread::AS_InSTA) {
COMPlusThrow(kNotSupportedException, W("NotSupported_SignalAndWaitSTAThread")); //<TODO> Change this message
}
#endif
DWORD res = (DWORD) -1;
HANDLE handles[2];
handles[0] = waitHandleSignalUNSAFE;
handles[1] = waitHandleWaitUNSAFE;
{
res = pThread->DoSignalAndWait(handles, timeout, TRUE /*alertable*/);
}
retVal = res;
HELPER_METHOD_FRAME_END();
return retVal;
}
FCIMPLEND
|