forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Windows IO completions to the portable thread pool (d…
…otnet#64834) * Add support for Windows IO completions to the portable thread pool - Added an implementation for BindHandle - Polling for IO completions is done in batches on separate threads similarly to what is done on Unixes - Added a high-priority work item queue to have IO completion work items run at higher priority - Removed the time-sensitive work item queue, used the high-priority queue instead
- Loading branch information
Showing
85 changed files
with
1,255 additions
and
816 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/coreclr/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.Windows.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// 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); | ||
} | ||
|
||
if (UsePortableThreadPoolForIO) | ||
{ | ||
// OS doesn't signal handle, so do it here | ||
overlapped->InternalLow = IntPtr.Zero; | ||
|
||
PortableThreadPool.ThreadPoolInstance.QueueNativeOverlapped(overlapped); | ||
return true; | ||
} | ||
|
||
return PostQueuedCompletionStatus(overlapped); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.InternalCall)] | ||
private static extern unsafe bool PostQueuedCompletionStatus(NativeOverlapped* overlapped); | ||
|
||
[Obsolete("ThreadPool.BindHandle(IntPtr) has been deprecated. Use ThreadPool.BindHandle(SafeHandle) instead.")] | ||
[SupportedOSPlatform("windows")] | ||
public static bool BindHandle(IntPtr osHandle) | ||
{ | ||
if (UsePortableThreadPoolForIO) | ||
{ | ||
PortableThreadPool.ThreadPoolInstance.RegisterForIOCompletionNotifications(osHandle); | ||
return true; | ||
} | ||
|
||
return BindIOCompletionCallbackNative(osHandle); | ||
} | ||
|
||
[SupportedOSPlatform("windows")] | ||
public static bool BindHandle(SafeHandle osHandle!!) | ||
{ | ||
bool mustReleaseSafeHandle = false; | ||
try | ||
{ | ||
osHandle.DangerousAddRef(ref mustReleaseSafeHandle); | ||
|
||
if (UsePortableThreadPoolForIO) | ||
{ | ||
PortableThreadPool.ThreadPoolInstance.RegisterForIOCompletionNotifications(osHandle.DangerousGetHandle()); | ||
return true; | ||
} | ||
|
||
return BindIOCompletionCallbackNative(osHandle.DangerousGetHandle()); | ||
} | ||
finally | ||
{ | ||
if (mustReleaseSafeHandle) | ||
osHandle.DangerousRelease(); | ||
} | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.InternalCall)] | ||
private static extern bool BindIOCompletionCallbackNative(IntPtr fileHandle); | ||
} | ||
} |
Oops, something went wrong.