refactor: use System.Threading.Lock for the remaining monitor locks#851
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Completes the
System.Threading.Lockmigration.ActivityLogServicewas alreadyconverted; this brings the remaining six monitor locks to the same idiom. No
behavior change —
lock(Lock)lowers toEnterScope()/Dispose(), identicalmutual exclusion to a
lock(object)monitor.Changes
private readonly object _x = new()→private readonly Lock _x = new()in:Services/AppAlertService.cs—_watcherLockServices/IconExtractorService.cs—_evictionLock(static)Services/PingMonitorService.cs—_stateLockServices/SystemInfoService.cs—_cacheLockServices/TracerouteMonitorService.cs—_stateLockViewModels/ConsoleViewModel.cs—_gateWhy
LockThe dedicated lock type makes "this field exists only to be locked on" explicit at
the type level, lets the analyzer flag accidental
Monitor/Wait/Pulsemisuse,and uses the lighter
EnterScopelock path.System.Threadingis already in theproject's implicit usings, so no
usingchange is needed.Verification
lock()target — noMonitor.Wait/Pulse,not passed as an argument, not locked from outside the declaring type.
lock()statement sites compile unchanged against the new type.Behavior identical (Protocol Q).
refactor:→ no release.