/
ThreadPool.CoreCLR.Windows.cs
56 lines (48 loc) · 1.83 KB
/
ThreadPool.CoreCLR.Windows.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace System.Threading
{
public static partial class ThreadPool
{
[CLSCompliant(false)]
[SupportedOSPlatform("windows")]
public static unsafe bool UnsafeQueueNativeOverlapped(NativeOverlapped* overlapped)
{
if (overlapped == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.overlapped);
}
// OS doesn't signal handle, so do it here
overlapped->InternalLow = IntPtr.Zero;
PortableThreadPool.ThreadPoolInstance.QueueNativeOverlapped(overlapped);
return true;
}
[Obsolete("ThreadPool.BindHandle(IntPtr) has been deprecated. Use ThreadPool.BindHandle(SafeHandle) instead.")]
[SupportedOSPlatform("windows")]
public static bool BindHandle(IntPtr osHandle)
{
PortableThreadPool.ThreadPoolInstance.RegisterForIOCompletionNotifications(osHandle);
return true;
}
[SupportedOSPlatform("windows")]
public static bool BindHandle(SafeHandle osHandle)
{
ArgumentNullException.ThrowIfNull(osHandle);
bool mustReleaseSafeHandle = false;
try
{
osHandle.DangerousAddRef(ref mustReleaseSafeHandle);
PortableThreadPool.ThreadPoolInstance.RegisterForIOCompletionNotifications(osHandle.DangerousGetHandle());
return true;
}
finally
{
if (mustReleaseSafeHandle)
osHandle.DangerousRelease();
}
}
}
}