Fix race condition in ContentManager
This fix a race condition happening since #791 when trying to load a game via command line.
This commit is contained in:
parent
78f6b1d396
commit
afc59e758a
1 changed files with 154 additions and 124 deletions
|
@ -28,6 +28,8 @@ namespace Ryujinx.HLE.FileSystem.Content
|
|||
|
||||
private Switch _device;
|
||||
|
||||
private readonly object _lock = new object();
|
||||
|
||||
public ContentManager(Switch device)
|
||||
{
|
||||
_contentDictionary = new SortedDictionary<(ulong, NcaContentType), string>();
|
||||
|
@ -57,6 +59,8 @@ namespace Ryujinx.HLE.FileSystem.Content
|
|||
}
|
||||
|
||||
public void LoadEntries(bool ignoreMissingFonts = false)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_contentDictionary = new SortedDictionary<(ulong, NcaContentType), string>();
|
||||
_locationEntries = new Dictionary<StorageId, LinkedList<LocationEntry>>();
|
||||
|
@ -156,13 +160,19 @@ namespace Ryujinx.HLE.FileSystem.Content
|
|||
|
||||
_device.System.Font.Initialize(this, ignoreMissingFonts);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearEntry(long titleId, NcaContentType contentType, StorageId storageId)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
RemoveLocationEntry(titleId, contentType, storageId);
|
||||
}
|
||||
}
|
||||
|
||||
public void RefreshEntries(StorageId storageId, int flag)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
LinkedList<LocationEntry> locationList = _locationEntries[storageId];
|
||||
LinkedListNode<LocationEntry> locationEntry = locationList.First;
|
||||
|
@ -179,8 +189,11 @@ namespace Ryujinx.HLE.FileSystem.Content
|
|||
locationEntry = nextLocationEntry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasNca(string ncaId, StorageId storageId)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_contentDictionary.ContainsValue(ncaId))
|
||||
{
|
||||
|
@ -192,29 +205,38 @@ namespace Ryujinx.HLE.FileSystem.Content
|
|||
|
||||
return storage == storageId;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public UInt128 GetInstalledNcaId(long titleId, NcaContentType contentType)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_contentDictionary.ContainsKey(((ulong)titleId, contentType)))
|
||||
{
|
||||
return new UInt128(_contentDictionary[((ulong)titleId, contentType)]);
|
||||
}
|
||||
}
|
||||
|
||||
return new UInt128();
|
||||
}
|
||||
|
||||
public StorageId GetInstalledStorage(long titleId, NcaContentType contentType, StorageId storageId)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
LocationEntry locationEntry = GetLocation(titleId, contentType, storageId);
|
||||
|
||||
return locationEntry.ContentPath != null ?
|
||||
LocationHelper.GetStorageId(locationEntry.ContentPath) : StorageId.None;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetInstalledContentPath(long titleId, StorageId storageId, NcaContentType contentType)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
LocationEntry locationEntry = GetLocation(titleId, contentType, storageId);
|
||||
|
||||
|
@ -222,11 +244,14 @@ namespace Ryujinx.HLE.FileSystem.Content
|
|||
{
|
||||
return locationEntry.ContentPath;
|
||||
}
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public void RedirectLocation(LocationEntry newEntry, StorageId storageId)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
LocationEntry locationEntry = GetLocation(newEntry.TitleId, newEntry.ContentType, storageId);
|
||||
|
||||
|
@ -237,6 +262,7 @@ namespace Ryujinx.HLE.FileSystem.Content
|
|||
|
||||
AddLocationEntry(newEntry, storageId);
|
||||
}
|
||||
}
|
||||
|
||||
private bool VerifyContentType(LocationEntry locationEntry, NcaContentType contentType)
|
||||
{
|
||||
|
@ -827,6 +853,8 @@ namespace Ryujinx.HLE.FileSystem.Content
|
|||
{
|
||||
LoadEntries(true);
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
var locationEnties = _locationEntries[StorageId.NandSystem];
|
||||
|
||||
foreach (var entry in locationEnties)
|
||||
|
@ -852,6 +880,8 @@ namespace Ryujinx.HLE.FileSystem.Content
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue