mirror of https://github.com/ppy/osu
Add explicit lock object and some xmldoc for clarity
This commit is contained in:
parent
dc21aebdc7
commit
6cc0bf17a9
|
@ -30,9 +30,23 @@ public class BeatmapDifficultyCache : MemoryCachingComponent<BeatmapDifficultyCa
|
|||
// Too many simultaneous updates can lead to stutters. One thread seems to work fine for song select display purposes.
|
||||
private readonly ThreadedTaskScheduler updateScheduler = new ThreadedTaskScheduler(1, nameof(BeatmapDifficultyCache));
|
||||
|
||||
// All bindables that should be updated along with the current ruleset + mods.
|
||||
/// <summary>
|
||||
/// All bindables that should be updated along with the current ruleset + mods.
|
||||
/// </summary>
|
||||
private readonly WeakList<BindableStarDifficulty> trackedBindables = new WeakList<BindableStarDifficulty>();
|
||||
|
||||
/// <summary>
|
||||
/// Cancellation sources used by tracked bindables.
|
||||
/// </summary>
|
||||
private readonly List<CancellationTokenSource> linkedCancellationSources = new List<CancellationTokenSource>();
|
||||
|
||||
/// <summary>
|
||||
/// Lock to be held when operating on <see cref="trackedBindables"/> or <see cref="linkedCancellationSources"/>.
|
||||
/// </summary>
|
||||
private readonly object bindableUpdateLock = new object();
|
||||
|
||||
private CancellationTokenSource trackedUpdateCancellationSource;
|
||||
|
||||
[Resolved]
|
||||
private BeatmapManager beatmapManager { get; set; }
|
||||
|
||||
|
@ -60,7 +74,7 @@ public IBindable<StarDifficulty> 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<CancellationTokenSource> linkedCancellationSources = new List<CancellationTokenSource>();
|
||||
|
||||
/// <summary>
|
||||
/// Updates all tracked <see cref="BindableStarDifficulty"/> using the current ruleset and mods.
|
||||
/// </summary>
|
||||
private void updateTrackedBindables()
|
||||
{
|
||||
lock (trackedBindables)
|
||||
lock (bindableUpdateLock)
|
||||
{
|
||||
cancelTrackedBindableUpdate();
|
||||
trackedUpdateCancellationSource = new CancellationTokenSource();
|
||||
|
@ -172,7 +183,7 @@ private void updateTrackedBindables()
|
|||
/// </summary>
|
||||
private void cancelTrackedBindableUpdate()
|
||||
{
|
||||
lock (trackedBindables)
|
||||
lock (bindableUpdateLock)
|
||||
{
|
||||
trackedUpdateCancellationSource?.Cancel();
|
||||
trackedUpdateCancellationSource = null;
|
||||
|
|
Loading…
Reference in New Issue