Remove unnecessary locking; operations are now thread-safe

This commit is contained in:
Dean Herbert 2017-10-18 13:48:15 +09:00
parent 2f3319552d
commit cf5290fead

View File

@ -287,8 +287,7 @@ namespace osu.Game.Beatmaps
/// <param name="beatmapSet">The beatmap set to delete.</param> /// <param name="beatmapSet">The beatmap set to delete.</param>
public void Delete(BeatmapSetInfo beatmapSet) public void Delete(BeatmapSetInfo beatmapSet)
{ {
lock (beatmaps) if (!beatmaps.Delete(beatmapSet)) return;
if (!beatmaps.Delete(beatmapSet)) return;
if (!beatmapSet.Protected) if (!beatmapSet.Protected)
files.Dereference(beatmapSet.Files.Select(f => f.FileInfo).ToArray()); files.Dereference(beatmapSet.Files.Select(f => f.FileInfo).ToArray());
@ -298,21 +297,13 @@ namespace osu.Game.Beatmaps
/// Delete a beatmap difficulty. /// Delete a beatmap difficulty.
/// </summary> /// </summary>
/// <param name="beatmap">The beatmap difficulty to hide.</param> /// <param name="beatmap">The beatmap difficulty to hide.</param>
public void Hide(BeatmapInfo beatmap) public void Hide(BeatmapInfo beatmap) => beatmaps.Hide(beatmap);
{
lock (beatmaps)
beatmaps.Hide(beatmap);
}
/// <summary> /// <summary>
/// Restore a beatmap difficulty. /// Restore a beatmap difficulty.
/// </summary> /// </summary>
/// <param name="beatmap">The beatmap difficulty to restore.</param> /// <param name="beatmap">The beatmap difficulty to restore.</param>
public void Restore(BeatmapInfo beatmap) public void Restore(BeatmapInfo beatmap) => beatmaps.Restore(beatmap);
{
lock (beatmaps)
beatmaps.Restore(beatmap);
}
/// <summary> /// <summary>
/// Returns a <see cref="BeatmapSetInfo"/> to a usable state if it has previously been deleted but not yet purged. /// Returns a <see cref="BeatmapSetInfo"/> to a usable state if it has previously been deleted but not yet purged.
@ -321,8 +312,7 @@ namespace osu.Game.Beatmaps
/// <param name="beatmapSet">The beatmap to restore.</param> /// <param name="beatmapSet">The beatmap to restore.</param>
private void undelete(BeatmapStore beatmaps, FileStore files, BeatmapSetInfo beatmapSet) private void undelete(BeatmapStore beatmaps, FileStore files, BeatmapSetInfo beatmapSet)
{ {
lock (beatmaps) if (!beatmaps.Undelete(beatmapSet)) return;
if (!beatmaps.Undelete(beatmapSet)) return;
if (!beatmapSet.Protected) if (!beatmapSet.Protected)
files.Reference(beatmapSet.Files.Select(f => f.FileInfo).ToArray()); files.Reference(beatmapSet.Files.Select(f => f.FileInfo).ToArray());
@ -357,11 +347,7 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
/// <param name="query">The query.</param> /// <param name="query">The query.</param>
/// <returns>The first result for the provided query, or null if no results were found.</returns> /// <returns>The first result for the provided query, or null if no results were found.</returns>
public BeatmapSetInfo QueryBeatmapSet(Func<BeatmapSetInfo, bool> query) public BeatmapSetInfo QueryBeatmapSet(Func<BeatmapSetInfo, bool> query) => beatmaps.BeatmapSets.FirstOrDefault(query);
{
lock (beatmaps)
return beatmaps.BeatmapSets.FirstOrDefault(query);
}
/// <summary> /// <summary>
/// Refresh an existing instance of a <see cref="BeatmapSetInfo"/> from the store. /// Refresh an existing instance of a <see cref="BeatmapSetInfo"/> from the store.
@ -375,33 +361,21 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
/// <param name="query">The query.</param> /// <param name="query">The query.</param>
/// <returns>Results from the provided query.</returns> /// <returns>Results from the provided query.</returns>
public List<BeatmapSetInfo> QueryBeatmapSets(Func<BeatmapSetInfo, bool> query) public List<BeatmapSetInfo> QueryBeatmapSets(Func<BeatmapSetInfo, bool> query) => beatmaps.BeatmapSets.Where(query).ToList();
{
lock (beatmaps)
return beatmaps.BeatmapSets.Where(query).ToList();
}
/// <summary> /// <summary>
/// Perform a lookup query on available <see cref="BeatmapInfo"/>s. /// Perform a lookup query on available <see cref="BeatmapInfo"/>s.
/// </summary> /// </summary>
/// <param name="query">The query.</param> /// <param name="query">The query.</param>
/// <returns>The first result for the provided query, or null if no results were found.</returns> /// <returns>The first result for the provided query, or null if no results were found.</returns>
public BeatmapInfo QueryBeatmap(Func<BeatmapInfo, bool> query) public BeatmapInfo QueryBeatmap(Func<BeatmapInfo, bool> query) => beatmaps.Beatmaps.FirstOrDefault(query);
{
lock (beatmaps)
return beatmaps.Beatmaps.FirstOrDefault(query);
}
/// <summary> /// <summary>
/// Perform a lookup query on available <see cref="BeatmapInfo"/>s. /// Perform a lookup query on available <see cref="BeatmapInfo"/>s.
/// </summary> /// </summary>
/// <param name="query">The query.</param> /// <param name="query">The query.</param>
/// <returns>Results from the provided query.</returns> /// <returns>Results from the provided query.</returns>
public List<BeatmapInfo> QueryBeatmaps(Func<BeatmapInfo, bool> query) public List<BeatmapInfo> QueryBeatmaps(Func<BeatmapInfo, bool> query) => beatmaps.Beatmaps.Where(query).ToList();
{
lock (beatmaps)
return beatmaps.Beatmaps.Where(query).ToList();
}
/// <summary> /// <summary>
/// Creates an <see cref="ArchiveReader"/> from a valid storage path. /// Creates an <see cref="ArchiveReader"/> from a valid storage path.
@ -437,9 +411,7 @@ namespace osu.Game.Beatmaps
var hash = hashable.ComputeSHA2Hash(); var hash = hashable.ComputeSHA2Hash();
// check if this beatmap has already been imported and exit early if so. // check if this beatmap has already been imported and exit early if so.
BeatmapSetInfo beatmapSet; var beatmapSet = beatmaps.BeatmapSets.FirstOrDefault(b => b.Hash == hash);
lock (beatmaps)
beatmapSet = beatmaps.BeatmapSets.FirstOrDefault(b => b.Hash == hash);
if (beatmapSet != null) if (beatmapSet != null)
{ {
@ -523,8 +495,7 @@ namespace osu.Game.Beatmaps
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns> /// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
public List<BeatmapSetInfo> GetAllUsableBeatmapSets() public List<BeatmapSetInfo> GetAllUsableBeatmapSets()
{ {
lock (beatmaps) return beatmaps.BeatmapSets.Where(s => !s.DeletePending).ToList();
return beatmaps.BeatmapSets.Where(s => !s.DeletePending).ToList();
} }
protected class BeatmapManagerWorkingBeatmap : WorkingBeatmap protected class BeatmapManagerWorkingBeatmap : WorkingBeatmap