Skip to content

Cleanup uses of Interlocked.CompareExchange<object> #117858

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

Merged
merged 2 commits into from
Jul 20, 2025

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Jul 20, 2025

No description provided.

@Copilot Copilot AI review requested due to automatic review settings July 20, 2025 04:49
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jul 20, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modernizes the codebase by simplifying singleton lazy initialization patterns that previously used verbose Interlocked.CompareExchange<object> implementations. The changes leverage C# 13's implicit backing field feature to create more concise and readable code while maintaining the same thread-safe behavior.

  • Replaces verbose property getters with expression-bodied properties using implicit backing fields
  • Removes explicit generic type parameters from Interlocked.CompareExchange calls where type inference is sufficient
  • Simplifies one method from property to expression-bodied syntax

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/libraries/System.Text.Encoding.CodePages/src/System/Text/SBCSCodePageEncoding.cs Modernizes InternalSyncObject property using implicit backing field pattern
src/libraries/System.Text.Encoding.CodePages/src/System/Text/EncoderBestFitFallback.cs Modernizes InternalSyncObject property using implicit backing field pattern
src/libraries/System.Text.Encoding.CodePages/src/System/Text/DecoderBestFitFallback.cs Modernizes InternalSyncObject property using implicit backing field pattern
src/libraries/System.Text.Encoding.CodePages/src/System/Text/DBCSCodePageEncoding.cs Modernizes InternalSyncObject property using implicit backing field pattern
src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaSet.cs Modernizes InternalSyncObject property using implicit backing field pattern
src/libraries/System.Private.CoreLib/src/System/TimeZone.cs Modernizes InternalSyncObject property using implicit backing field pattern
src/libraries/System.Diagnostics.TraceSource/src/System/Diagnostics/Switch.cs Modernizes InitializedLock property using implicit backing field pattern
src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs Modernizes SyncRoot property and simplifies GetUnderlyingNativeHandle method
src/coreclr/System.Private.CoreLib/src/System/MulticastDelegate.CoreCLR.cs Removes explicit generic type parameter from Interlocked.CompareExchange call

@jkotas
Copy link
Member Author

jkotas commented Jul 20, 2025

Context dotnet/dotnet-api-docs#11422 (comment)

@jkotas jkotas requested a review from stephentoub July 20, 2025 04:52
@jkotas jkotas force-pushed the compareexchange branch from 39691b6 to 0300b04 Compare July 20, 2025 05:17
@jkotas jkotas force-pushed the compareexchange branch from 0300b04 to 6d4e98b Compare July 20, 2025 05:57
@am11 am11 added area-System.Threading and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jul 20, 2025
Copy link
Member

@am11 am11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing using System.Threading; in a few places.

@jkotas jkotas requested a review from MichalStrehovsky as a code owner July 20, 2025 10:39
@jkotas
Copy link
Member Author

jkotas commented Jul 20, 2025

/ba-g infrastructure timeouts

@jkotas jkotas merged commit b3037c6 into dotnet:main Jul 20, 2025
119 of 143 checks passed
@jkotas jkotas deleted the compareexchange branch July 20, 2025 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants