-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Refactor lock upgrade logic #122571
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
Refactor lock upgrade logic #122571
Changes from 7 commits
7bf6476
01bb0c0
9012d7d
183af37
4bc6c3a
c4ab2dd
d98cfa1
d26ade6
59df8b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
@@ -127,6 +128,26 @@ | |
| [MethodImpl(MethodImplOptions.InternalCall)] | ||
| private static extern int CompareExchange32(ref int location1, int value, int comparand); | ||
|
|
||
| // This is used internally in cases where having a managed | ||
| // ref to the location is unsafe (Ex: it is the object header of a pinned object). | ||
| // The intrinsic expansion for this overload is exactly the same as for the `ref int` | ||
| // variant and will go on the same path since expansion is triggered by the name and | ||
| // return type of the method. | ||
| // The important part is avoiding `ref *location` that is reported as byref to the GC. | ||
|
Check failure on line 136 in src/coreclr/System.Private.CoreLib/src/System/Threading/Interlocked.CoreCLR.cs
|
||
| [Intrinsic] | ||
| internal static unsafe int CompareExchange(int* location1, int value, int comparand) | ||
| { | ||
| #if TARGET_X86 || TARGET_64BIT | ||
jkotas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return CompareExchange(location1, value, comparand); // Must expand intrinsic | ||
| #else | ||
| Debug.Assert(location1 != null); | ||
jkoritzinsky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return CompareExchange32Pointer(location1, value, comparand); | ||
| #endif | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.InternalCall)] | ||
| private static unsafe extern int CompareExchange32Pointer(int* location1, int value, int comparand); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. osx-arm64 build is failing, fix: #122753.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was it not detected by the CI?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Analyzers should run for all build flavors by default. I do not think we have any conditions that enable them for debug builds only. Also, I am not able to reproduce the error on Windows (tried |
||
|
|
||
| /// <summary>Compares two 64-bit signed integers for equality and, if they are equal, replaces the first value.</summary> | ||
| /// <param name="location1">The destination, whose value is compared with <paramref name="comparand"/> and possibly replaced.</param> | ||
| /// <param name="value">The value that replaces the destination value if the comparison results in equality.</param> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,13 +24,12 @@ | |
| #endif | ||
| } | ||
|
|
||
| // This is used internally by NativeAOT runtime in cases where having a managed | ||
| // ref to the location is unsafe (Ex: it is the syncblock of a pinned object). | ||
| // This is used internally in cases where having a managed | ||
| // ref to the location is unsafe (Ex: it is the object header of a pinned object). | ||
| // The intrinsic expansion for this overload is exactly the same as for the `ref int` | ||
| // variant and will go on the same path since expansion is triggered by the name and | ||
| // return type of the method. | ||
| // The important part is avoiding `ref *location` in the unexpanded scenario, like | ||
| // in a case when compiling the Debug flavor of the app. | ||
| // The important part is avoiding `ref *location` that is reported as byref to the GC. | ||
|
Check failure on line 32 in src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Interlocked.cs
|
||
jkotas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [Intrinsic] | ||
| internal static unsafe int CompareExchange(int* location1, int value, int comparand) | ||
| { | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.