-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port some CoreRT Threading classes to Mono #47333
Merged
marek-safar
merged 36 commits into
dotnet:main
from
CoffeeFlux:corert-threading-changes
Mar 13, 2021
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
ac37cf0
Remove appropriate icalls from Mono
CoffeeFlux b58f7c3
Wire up the build
CoffeeFlux 515a552
Remove old Mono managed implementations
CoffeeFlux 549cb47
Miscellaneous additions and changes needed for porting
CoffeeFlux 4591f0f
Add Thread._waitInfo and switch over usage
CoffeeFlux ccb76f4
Attempt to annotate the new files
CoffeeFlux 64c4abf
Fix todo
CoffeeFlux f53dc2c
Fix Windows build
CoffeeFlux 8add4e0
Back to WaitInfo
CoffeeFlux 13e5c80
Annotation fixes
CoffeeFlux 990efa1
Add WaitHandle.Windows.cs
CoffeeFlux 64c3af0
Rename to just FeatureManagedThreading and add WaitHandle.Windows.cs
CoffeeFlux 8d1d8b0
Thread down stack size as part of thread creation
CoffeeFlux 1e910a4
No separate feature flag
CoffeeFlux f5c3654
Expose property correctly
CoffeeFlux 04d486a
Add Windows Interop files
CoffeeFlux b6bf424
Disable reentrant wait functionality
CoffeeFlux b24af36
Attempt to fix wasm
CoffeeFlux 051fd47
Fix ifdefs
CoffeeFlux 100c14a
Switch bool to BOOL for interop
CoffeeFlux 1a865ce
Always create _waitInfo
CoffeeFlux aed3aac
Some exclusions
CoffeeFlux 942b575
Re-enable the tests and disable the name check
CoffeeFlux 616188c
Remove thread_interrupt_requested
CoffeeFlux 61de05a
Correctly abandon mutexes
CoffeeFlux 2a12e3f
Disable tests again
CoffeeFlux b84385f
Uncomment unsupported name exception
CoffeeFlux 17ba865
Excise a lot more runtime code
CoffeeFlux bb3ae83
Disable another test
CoffeeFlux 696fc10
Windows build fix
CoffeeFlux 65801bd
Disable InterruptTest on Windows
CoffeeFlux 3472b0b
Add link to issue on reentrant wait support for Windows
CoffeeFlux def05ab
Move mutex abandoning to the managed Thread object's finalizer
CoffeeFlux 891987b
Rethrow with InvalidOperationException when called from WaitHandle
CoffeeFlux a9dd5c3
Another ActiveIssue on Windows
CoffeeFlux cc14788
Linker exclusion no longer needed
CoffeeFlux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetLastError.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,14 @@ | ||
// 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.InteropServices; | ||
|
||
internal partial class Interop | ||
{ | ||
internal partial class Kernel32 | ||
{ | ||
[DllImport(Libraries.Kernel32)] | ||
[SuppressGCTransition] | ||
internal static extern int GetLastError(); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.Threading.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 Microsoft.Win32.SafeHandles; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Kernel32 | ||
{ | ||
internal const int WAIT_FAILED = unchecked((int)0xFFFFFFFF); | ||
|
||
[DllImport(Libraries.Kernel32)] | ||
internal static extern uint WaitForMultipleObjectsEx(uint nCount, IntPtr lpHandles, BOOL bWaitAll, uint dwMilliseconds, BOOL bAlertable); | ||
|
||
[DllImport(Libraries.Kernel32)] | ||
internal static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds); | ||
|
||
[DllImport(Libraries.Kernel32)] | ||
internal static extern uint SignalObjectAndWait(IntPtr hObjectToSignal, IntPtr hObjectToWaitOn, uint dwMilliseconds, BOOL bAlertable); | ||
|
||
[DllImport(Libraries.Kernel32)] | ||
internal static extern void Sleep(uint milliseconds); | ||
|
||
internal const uint CREATE_SUSPENDED = 0x00000004; | ||
internal const uint STACK_SIZE_PARAM_IS_A_RESERVATION = 0x00010000; | ||
|
||
[DllImport(Libraries.Kernel32)] | ||
internal static extern unsafe SafeWaitHandle CreateThread( | ||
IntPtr lpThreadAttributes, | ||
IntPtr dwStackSize, | ||
delegate* unmanaged<IntPtr, uint> lpStartAddress, | ||
IntPtr lpParameter, | ||
uint dwCreationFlags, | ||
out uint lpThreadId); | ||
|
||
[DllImport(Libraries.Kernel32)] | ||
internal static extern uint ResumeThread(SafeWaitHandle hThread); | ||
|
||
[DllImport(Libraries.Kernel32)] | ||
internal static extern IntPtr GetCurrentThread(); | ||
|
||
internal const int DUPLICATE_SAME_ACCESS = 2; | ||
|
||
[DllImport(Libraries.Kernel32, SetLastError = true)] | ||
internal static extern bool DuplicateHandle( | ||
IntPtr hSourceProcessHandle, | ||
IntPtr hSourceHandle, | ||
IntPtr hTargetProcessHandle, | ||
out SafeWaitHandle lpTargetHandle, | ||
uint dwDesiredAccess, | ||
bool bInheritHandle, | ||
uint dwOptions); | ||
|
||
internal enum ThreadPriority : int | ||
{ | ||
Idle = -15, | ||
Lowest = -2, | ||
BelowNormal = -1, | ||
Normal = 0, | ||
AboveNormal = 1, | ||
Highest = 2, | ||
TimeCritical = 15, | ||
|
||
ErrorReturn = 0x7FFFFFFF | ||
} | ||
|
||
[DllImport(Libraries.Kernel32)] | ||
internal static extern ThreadPriority GetThreadPriority(SafeWaitHandle hThread); | ||
|
||
[DllImport(Libraries.Kernel32)] | ||
internal static extern bool SetThreadPriority(SafeWaitHandle hThread, int nPriority); | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be better to move to the caller. It seems to do always do some error checking which is Windows specific
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have to match the Windows equivalent here, since otherwise you end up with a bunch of weird platform-specific code at a higher level? Maybe I'm misunderstanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was referring to code patterns like
runtime/src/libraries/System.Private.CoreLib/src/System/Threading/EventWaitHandle.cs
Lines 32 to 45 in 1d9e50c