-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Conversation
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.
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 |
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.
Missing using System.Threading;
in a few places.
/ba-g infrastructure timeouts |
No description provided.