1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 10:42:54 +08:00

Add locking around async beatmap (task) retrieval

This commit is contained in:
Dean Herbert 2021-10-14 15:39:08 +09:00
parent 2e0a2a28ab
commit 060bb1afbd

View File

@ -205,7 +205,13 @@ namespace osu.Game.Beatmaps
return new CancellationTokenSource(timeout ?? TimeSpan.FromSeconds(10)); return new CancellationTokenSource(timeout ?? TimeSpan.FromSeconds(10));
} }
private Task<IBeatmap> loadBeatmapAsync() => beatmapLoadTask ??= Task.Factory.StartNew(() => private readonly object beatmapFetchLock = new object();
private Task<IBeatmap> loadBeatmapAsync()
{
lock (beatmapFetchLock)
{
return beatmapLoadTask ??= Task.Factory.StartNew(() =>
{ {
// Todo: Handle cancellation during beatmap parsing // Todo: Handle cancellation during beatmap parsing
var b = GetBeatmap() ?? new Beatmap(); var b = GetBeatmap() ?? new Beatmap();
@ -218,6 +224,8 @@ namespace osu.Game.Beatmaps
return b; return b;
}, loadCancellation.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default); }, loadCancellation.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
}
public override string ToString() => BeatmapInfo.ToString(); public override string ToString() => BeatmapInfo.ToString();