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.
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
Remove helper method frames from Monitors #113242
Remove helper method frames from Monitors #113242
Changes from 1 commit
48a66d5
5ba5cf7
66fa763
82a4d2e
5a31471
d42f4ec
e1199d5
426b8ff
3d942ff
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
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.
Can Exit_FastPath do anything when returning exitBehavior != LeaveHelperAction.None (note NOT EQUAL) that would break the subsequent fall-through to Exit_Slowpath (e.g. we did the fast-path exit, but it needs some other LeaveHelperAction... but we've done the Exit already)?
(same question on line 174)
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.
No.
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.
Can
Exit_FastPath
do anything when returningexitBehavior != LeaveHelperAction.None
(note NOT EQUAL) that would break the subsequent fall-through toExit_Slowpath
(e.g. we did the fast-path exit, but it needs some other LeaveHelperAction... but we've done the Exit already)?(same question on line 154)
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.
No.
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.
The TryEnter_Timeout_WithLockTaken method does not handle cases where timeout is less than -1. It is recommended to add an explicit check and throw an ArgumentException when timeout is invalid.
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
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.
Will this result in up to two
timeout
periods elapsing if the fast-path tried and returned anything other than Entered or Contention?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.
No, the timeout input to the fast path is only used to check against 0 (which has special meaning).
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
Check failure on line 234 in src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs#L234
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.
The TryEnter(object, int) method does not explicitly validate that millisecondsTimeout is not less than -1. To maintain the documented contract, consider adding a check to throw ArgumentException for invalid timeout values.
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
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.
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.
Should a
timeOut
of non-zero be handled, should it be passed down to/honored by theEnterObjMonitorHelperSpin
?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.
No, this is the fast set of spinning that waits for fractions of a millisecond or so, if you're willing to wait at all, we run the same amount of spinning for all possible timeouts.
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 should assert this here and do the error handling in managed code. The Copilot for the methods also called this out.