-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Bring back the reader-writer lock for RcwCache #120675
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
Instead of writing to `_cache` while under a reader lock, delay the cleanup until we can acquire a writer lock. We do this instead of doing an upgradeable lock as `ReaderWriterLockSlim` only supports one upgradeable reader thread at a time, removing the benefit of having an rwlock in the first place.
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 reverts a previous change that replaced a ReaderWriterLockSlim with a simple Lock in the RcwCache class, restoring the reader-writer lock mechanism for better concurrency. The change improves the cache's ability to handle concurrent read operations while ensuring thread-safe cleanup of dead entries.
Key changes:
- Replaces the simple
Lock
withReaderWriterLockSlim
for the RcwCache - Implements a two-phase locking strategy in
FindProxyForComInstance
to avoid upgradeable locks - Updates all cache operations to use appropriate read/write locks with proper try-finally blocks
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
Show resolved
Hide resolved
Tagging subscribers to this area: @dotnet/interop-contrib |
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
Show resolved
Hide resolved
…pServices/ComWrappers.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Instead of writing to
_cache
while under a reader lock, delay the cleanup until we can acquire a writer lock.We do this instead of doing an upgradeable lock as
ReaderWriterLockSlim
only supports one upgradeable reader thread at a time, removing the benefit of having an rwlock in the first place.This matches the logic in the .NET 9 CoreCLR implementation of ComWrappers.
Reverts #120370
Fixes #120470