mirror of
https://github.com/par274/sharpemu.git
synced 2026-09-01 22:31:17 +08:00
[ampr] allow concurrent reads
This commit is contained in:
@@ -6,6 +6,7 @@ using SharpEmu.Libs.Kernel;
|
|||||||
using System.Buffers;
|
using System.Buffers;
|
||||||
using System.Buffers.Binary;
|
using System.Buffers.Binary;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using Microsoft.Win32.SafeHandles;
|
||||||
|
|
||||||
namespace SharpEmu.Libs.Ampr;
|
namespace SharpEmu.Libs.Ampr;
|
||||||
|
|
||||||
@@ -43,17 +44,17 @@ public static class AmprExports
|
|||||||
{
|
{
|
||||||
public CachedHostFile(string path)
|
public CachedHostFile(string path)
|
||||||
{
|
{
|
||||||
Stream = new FileStream(
|
Handle = File.OpenHandle(
|
||||||
path,
|
path,
|
||||||
FileMode.Open,
|
FileMode.Open,
|
||||||
FileAccess.Read,
|
FileAccess.Read,
|
||||||
FileShare.ReadWrite | FileShare.Delete,
|
FileShare.ReadWrite | FileShare.Delete,
|
||||||
bufferSize: 1024 * 1024,
|
|
||||||
FileOptions.RandomAccess);
|
FileOptions.RandomAccess);
|
||||||
|
Length = RandomAccess.GetLength(Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Gate { get; } = new();
|
public SafeFileHandle Handle { get; }
|
||||||
public FileStream Stream { get; }
|
public long Length { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[SysAbiExport(
|
[SysAbiExport(
|
||||||
@@ -735,13 +736,7 @@ public static class AmprExports
|
|||||||
return openResult;
|
return openResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
long fileLength;
|
if (fileOffset >= (ulong)cachedFile.Length)
|
||||||
lock (cachedFile.Gate)
|
|
||||||
{
|
|
||||||
fileLength = cachedFile.Stream.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fileOffset >= (ulong)fileLength)
|
|
||||||
{
|
{
|
||||||
return (int)OrbisGen2Result.ORBIS_GEN2_OK;
|
return (int)OrbisGen2Result.ORBIS_GEN2_OK;
|
||||||
}
|
}
|
||||||
@@ -760,12 +755,10 @@ public static class AmprExports
|
|||||||
}
|
}
|
||||||
|
|
||||||
var request = (int)Math.Min((ulong)buffer.Length, size - bytesRead);
|
var request = (int)Math.Min((ulong)buffer.Length, size - bytesRead);
|
||||||
int read;
|
var read = RandomAccess.Read(
|
||||||
lock (cachedFile.Gate)
|
cachedFile.Handle,
|
||||||
{
|
buffer.AsSpan(0, request),
|
||||||
cachedFile.Stream.Position = unchecked((long)absoluteOffset);
|
unchecked((long)absoluteOffset));
|
||||||
read = cachedFile.Stream.Read(buffer, 0, request);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (read <= 0)
|
if (read <= 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user