mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 08:22:56 +08:00
Add locking around async beatmap (task) retrieval
This commit is contained in:
parent
2e0a2a28ab
commit
060bb1afbd
@ -205,19 +205,27 @@ 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()
|
||||||
{
|
{
|
||||||
// Todo: Handle cancellation during beatmap parsing
|
lock (beatmapFetchLock)
|
||||||
var b = GetBeatmap() ?? new Beatmap();
|
{
|
||||||
|
return beatmapLoadTask ??= Task.Factory.StartNew(() =>
|
||||||
|
{
|
||||||
|
// Todo: Handle cancellation during beatmap parsing
|
||||||
|
var b = GetBeatmap() ?? new Beatmap();
|
||||||
|
|
||||||
// The original beatmap version needs to be preserved as the database doesn't contain it
|
// The original beatmap version needs to be preserved as the database doesn't contain it
|
||||||
BeatmapInfo.BeatmapVersion = b.BeatmapInfo.BeatmapVersion;
|
BeatmapInfo.BeatmapVersion = b.BeatmapInfo.BeatmapVersion;
|
||||||
|
|
||||||
// Use the database-backed info for more up-to-date values (beatmap id, ranked status, etc)
|
// Use the database-backed info for more up-to-date values (beatmap id, ranked status, etc)
|
||||||
b.BeatmapInfo = BeatmapInfo;
|
b.BeatmapInfo = BeatmapInfo;
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user