mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Update BufferedStorage for 13.1.0
This commit is contained in:
parent
d2d73827ba
commit
c9a2056844
1 changed files with 10 additions and 8 deletions
|
@ -16,6 +16,7 @@ namespace LibHac.FsSystem;
|
|||
/// <summary>
|
||||
/// An <see cref="IStorage"/> that provides buffered access to a base <see cref="IStorage"/>.
|
||||
/// </summary>
|
||||
/// <remarks>Based on FS 13.1.0 (nnSdk 13.4.0)</remarks>
|
||||
public class BufferedStorage : IStorage
|
||||
{
|
||||
private const long InvalidOffset = long.MaxValue;
|
||||
|
@ -673,6 +674,8 @@ public class BufferedStorage : IStorage
|
|||
ref Cache end = ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(BufferedStorage._caches),
|
||||
BufferedStorage._cacheCount);
|
||||
|
||||
using var lk = new ScopedLock<SdkMutexType>(ref BufferedStorage._mutex);
|
||||
|
||||
// Validate the range.
|
||||
Assert.SdkAssert(!Unsafe.IsAddressLessThan(ref start,
|
||||
ref MemoryMarshal.GetArrayDataReference(BufferedStorage._caches)));
|
||||
|
@ -716,6 +719,8 @@ public class BufferedStorage : IStorage
|
|||
ref Cache end = ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(BufferedStorage._caches),
|
||||
BufferedStorage._cacheCount);
|
||||
|
||||
using var lk = new ScopedLock<SdkMutexType>(ref BufferedStorage._mutex);
|
||||
|
||||
// Validate the range.
|
||||
Assert.SdkAssert(!Unsafe.IsAddressLessThan(ref start,
|
||||
ref MemoryMarshal.GetArrayDataReference(BufferedStorage._caches)));
|
||||
|
@ -1161,10 +1166,7 @@ public class BufferedStorage : IStorage
|
|||
// Invalidate caches if needed.
|
||||
if (operationId == OperationId.InvalidateCache)
|
||||
{
|
||||
using var cache = new SharedCache(this);
|
||||
|
||||
while (cache.AcquireNextOverlappedCache(offset, size))
|
||||
cache.Invalidate();
|
||||
InvalidateCaches();
|
||||
}
|
||||
|
||||
return _baseStorage.OperateRange(outBuffer, operationId, offset, size, inBuffer);
|
||||
|
@ -1351,13 +1353,13 @@ public class BufferedStorage : IStorage
|
|||
while (true)
|
||||
{
|
||||
if (!cache.AcquireFetchableCache())
|
||||
return ResultFs.OutOfResource.Value;
|
||||
return ResultFs.OutOfResource.Log();
|
||||
|
||||
// Try to upgrade out SharedCache to a UniqueCache
|
||||
using var fetchCache = new UniqueCache(this);
|
||||
(Result Result, bool wasUpgradeSuccessful) upgradeResult = fetchCache.Upgrade(in cache);
|
||||
if (upgradeResult.Result.IsFailure())
|
||||
return upgradeResult.Result;
|
||||
return upgradeResult.Result.Miss();
|
||||
|
||||
// Fetch the data from the base storage into the cache buffer if successful
|
||||
if (upgradeResult.wasUpgradeSuccessful)
|
||||
|
@ -1676,12 +1678,12 @@ public class BufferedStorage : IStorage
|
|||
while (true)
|
||||
{
|
||||
if (!cache.AcquireFetchableCache())
|
||||
return ResultFs.OutOfResource.Value;
|
||||
return ResultFs.OutOfResource.Log();
|
||||
|
||||
using var fetchCache = new UniqueCache(this);
|
||||
(Result Result, bool wasUpgradeSuccessful) upgradeResult = fetchCache.Upgrade(in cache);
|
||||
if (upgradeResult.Result.IsFailure())
|
||||
return upgradeResult.Result;
|
||||
return upgradeResult.Result.Miss();
|
||||
|
||||
if (upgradeResult.wasUpgradeSuccessful)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue