Fix inconsistent lock usage in BeatmapManager

This commit is contained in:
TocoToucan 2017-10-15 21:56:33 +03:00
parent e7c7ebdd9d
commit 4a064da30f
2 changed files with 19 additions and 10 deletions

View File

@ -138,8 +138,9 @@ private void ensureLoaded(OsuGameBase osu, int timeout = 60000)
var set = queryBeatmapSets().First();
foreach (BeatmapInfo b in set.Beatmaps)
Assert.IsTrue(set.Beatmaps.Any(c => c.OnlineBeatmapID == b.OnlineBeatmapID));
Assert.IsTrue(set.Beatmaps.Count > 0);
Assert.IsTrue(set.Beatmaps.Count > 0);
var beatmap = store.GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 0))?.Beatmap;
Assert.IsTrue(beatmap?.HitObjects.Count > 0);

View File

@ -59,8 +59,6 @@ public class BeatmapManager
private readonly FileStore files;
private readonly OsuDbContext connection;
private readonly RulesetStore rulesets;
private readonly BeatmapStore beatmaps;
@ -92,7 +90,6 @@ public BeatmapManager(Storage storage, FileStore files, OsuDbContext connection,
this.storage = storage;
this.files = files;
this.connection = connection;
this.rulesets = rulesets;
this.api = api;
@ -163,7 +160,7 @@ public void Import(params string[] paths)
/// <param name="archiveReader">The beatmap to be imported.</param>
public BeatmapSetInfo Import(ArchiveReader archiveReader)
{
BeatmapSetInfo set = null;
BeatmapSetInfo set;
// let's only allow one concurrent import at a time for now.
lock (importLock)
@ -181,7 +178,8 @@ public void Import(BeatmapSetInfo beatmapSetInfo)
// If we have an ID then we already exist in the database.
if (beatmapSetInfo.ID != 0) return;
beatmaps.Add(beatmapSetInfo);
lock (beatmaps)
beatmaps.Add(beatmapSetInfo);
}
/// <summary>
@ -272,13 +270,21 @@ public void Delete(BeatmapSetInfo beatmapSet)
/// Delete a beatmap difficulty.
/// </summary>
/// <param name="beatmap">The beatmap difficulty to hide.</param>
public void Hide(BeatmapInfo beatmap) => beatmaps.Hide(beatmap);
public void Hide(BeatmapInfo beatmap)
{
lock (beatmaps)
beatmaps.Hide(beatmap);
}
/// <summary>
/// Restore a beatmap difficulty.
/// </summary>
/// <param name="beatmap">The beatmap difficulty to restore.</param>
public void Restore(BeatmapInfo beatmap) => beatmaps.Restore(beatmap);
public void Restore(BeatmapInfo beatmap)
{
lock (beatmaps)
beatmaps.Restore(beatmap);
}
/// <summary>
/// Returns a <see cref="BeatmapSetInfo"/> to a usable state if it has previously been deleted but not yet purged.
@ -287,7 +293,8 @@ public void Delete(BeatmapSetInfo beatmapSet)
/// <param name="beatmapSet">The beatmap to restore.</param>
public void Undelete(BeatmapSetInfo beatmapSet)
{
if (!beatmaps.Undelete(beatmapSet)) return;
lock (beatmaps)
if (!beatmaps.Undelete(beatmapSet)) return;
if (!beatmapSet.Protected)
files.Reference(beatmapSet.Files.Select(f => f.FileInfo).ToArray());
@ -361,7 +368,8 @@ public BeatmapSetInfo QueryBeatmapSet(Func<BeatmapSetInfo, bool> query)
/// <returns>Results from the provided query.</returns>
public List<BeatmapSetInfo> QueryBeatmapSets(Func<BeatmapSetInfo, bool> query)
{
return beatmaps.QueryAndPopulate(query);
lock (beatmaps)
return beatmaps.QueryAndPopulate(query);
}
/// <summary>