From 6cc0bf17a9c06333d35079c46531bbea7fb0fab6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 10 Nov 2020 14:31:27 +0900 Subject: [PATCH] Add explicit lock object and some xmldoc for clarity --- osu.Game/Beatmaps/BeatmapDifficultyCache.cs | 25 +++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapDifficultyCache.cs b/osu.Game/Beatmaps/BeatmapDifficultyCache.cs index eeb6075ef5..3b58062add 100644 --- a/osu.Game/Beatmaps/BeatmapDifficultyCache.cs +++ b/osu.Game/Beatmaps/BeatmapDifficultyCache.cs @@ -30,9 +30,23 @@ public class BeatmapDifficultyCache : MemoryCachingComponent + /// All bindables that should be updated along with the current ruleset + mods. + /// private readonly WeakList trackedBindables = new WeakList(); + /// + /// Cancellation sources used by tracked bindables. + /// + private readonly List linkedCancellationSources = new List(); + + /// + /// Lock to be held when operating on or . + /// + private readonly object bindableUpdateLock = new object(); + + private CancellationTokenSource trackedUpdateCancellationSource; + [Resolved] private BeatmapManager beatmapManager { get; set; } @@ -60,7 +74,7 @@ public IBindable GetBindableDifficulty([NotNull] BeatmapInfo bea { var bindable = createBindable(beatmapInfo, currentRuleset.Value, currentMods.Value, cancellationToken); - lock (trackedBindables) + lock (bindableUpdateLock) trackedBindables.Add(bindable); return bindable; @@ -144,15 +158,12 @@ public static DifficultyRating GetDifficultyRating(double starRating) return DifficultyRating.Easy; } - private CancellationTokenSource trackedUpdateCancellationSource; - private readonly List linkedCancellationSources = new List(); - /// /// Updates all tracked using the current ruleset and mods. /// private void updateTrackedBindables() { - lock (trackedBindables) + lock (bindableUpdateLock) { cancelTrackedBindableUpdate(); trackedUpdateCancellationSource = new CancellationTokenSource(); @@ -172,7 +183,7 @@ private void updateTrackedBindables() /// private void cancelTrackedBindableUpdate() { - lock (trackedBindables) + lock (bindableUpdateLock) { trackedUpdateCancellationSource?.Cancel(); trackedUpdateCancellationSource = null;