mirror of
https://github.com/ppy/osu
synced 2025-02-17 02:47:19 +00:00
Add explicit lock object and some xmldoc for clarity
This commit is contained in:
parent
dc21aebdc7
commit
6cc0bf17a9
@ -30,9 +30,23 @@ namespace osu.Game.Beatmaps
|
|||||||
// Too many simultaneous updates can lead to stutters. One thread seems to work fine for song select display purposes.
|
// 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));
|
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>();
|
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]
|
[Resolved]
|
||||||
private BeatmapManager beatmapManager { get; set; }
|
private BeatmapManager beatmapManager { get; set; }
|
||||||
|
|
||||||
@ -60,7 +74,7 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
var bindable = createBindable(beatmapInfo, currentRuleset.Value, currentMods.Value, cancellationToken);
|
var bindable = createBindable(beatmapInfo, currentRuleset.Value, currentMods.Value, cancellationToken);
|
||||||
|
|
||||||
lock (trackedBindables)
|
lock (bindableUpdateLock)
|
||||||
trackedBindables.Add(bindable);
|
trackedBindables.Add(bindable);
|
||||||
|
|
||||||
return bindable;
|
return bindable;
|
||||||
@ -144,15 +158,12 @@ namespace osu.Game.Beatmaps
|
|||||||
return DifficultyRating.Easy;
|
return DifficultyRating.Easy;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CancellationTokenSource trackedUpdateCancellationSource;
|
|
||||||
private readonly List<CancellationTokenSource> linkedCancellationSources = new List<CancellationTokenSource>();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates all tracked <see cref="BindableStarDifficulty"/> using the current ruleset and mods.
|
/// Updates all tracked <see cref="BindableStarDifficulty"/> using the current ruleset and mods.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void updateTrackedBindables()
|
private void updateTrackedBindables()
|
||||||
{
|
{
|
||||||
lock (trackedBindables)
|
lock (bindableUpdateLock)
|
||||||
{
|
{
|
||||||
cancelTrackedBindableUpdate();
|
cancelTrackedBindableUpdate();
|
||||||
trackedUpdateCancellationSource = new CancellationTokenSource();
|
trackedUpdateCancellationSource = new CancellationTokenSource();
|
||||||
@ -172,7 +183,7 @@ namespace osu.Game.Beatmaps
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void cancelTrackedBindableUpdate()
|
private void cancelTrackedBindableUpdate()
|
||||||
{
|
{
|
||||||
lock (trackedBindables)
|
lock (bindableUpdateLock)
|
||||||
{
|
{
|
||||||
trackedUpdateCancellationSource?.Cancel();
|
trackedUpdateCancellationSource?.Cancel();
|
||||||
trackedUpdateCancellationSource = null;
|
trackedUpdateCancellationSource = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user