[*] Improved IMemoryMappedFile API
[+] AuIO::Adapters::NewAsyncTransactionFromStreamSeekingPair
This commit is contained in:
parent
afbe942ffd
commit
66f3250983
@ -13,4 +13,7 @@ namespace Aurora::IO::Adapters
|
|||||||
AUKN_SYM AuSPtr<IAsyncTransaction> NewAsyncTransactionFromStreamSeekingReader(const AuSPtr<ISeekingReader> &pStreamReader, AuOptional<Aurora::Async::WorkerPId_t> workers);
|
AUKN_SYM AuSPtr<IAsyncTransaction> NewAsyncTransactionFromStreamSeekingReader(const AuSPtr<ISeekingReader> &pStreamReader, AuOptional<Aurora::Async::WorkerPId_t> workers);
|
||||||
AUKN_SYM AuSPtr<IAsyncTransaction> NewAsyncTransactionFromStreamWriter(const AuSPtr<IStreamWriter> &pStreamWriter, AuOptional<Aurora::Async::WorkerPId_t> workers);
|
AUKN_SYM AuSPtr<IAsyncTransaction> NewAsyncTransactionFromStreamWriter(const AuSPtr<IStreamWriter> &pStreamWriter, AuOptional<Aurora::Async::WorkerPId_t> workers);
|
||||||
AUKN_SYM AuSPtr<IAsyncTransaction> NewAsyncTransactionFromStreamSeekingWriter(const AuSPtr<ISeekingWriter> &pStreamWriter, AuOptional<Aurora::Async::WorkerPId_t> workers);
|
AUKN_SYM AuSPtr<IAsyncTransaction> NewAsyncTransactionFromStreamSeekingWriter(const AuSPtr<ISeekingWriter> &pStreamWriter, AuOptional<Aurora::Async::WorkerPId_t> workers);
|
||||||
|
AUKN_SYM AuSPtr<IAsyncTransaction> NewAsyncTransactionFromStreamSeekingPair(const AuSPtr<ISeekingReader> &pStreamReader,
|
||||||
|
const AuSPtr<ISeekingWriter> &pStreamWriter,
|
||||||
|
AuOptional<Aurora::Async::WorkerPId_t> workers);
|
||||||
}
|
}
|
@ -11,6 +11,7 @@ namespace Aurora::IO::FS
|
|||||||
{
|
{
|
||||||
struct IMemoryMappedFile
|
struct IMemoryMappedFile
|
||||||
{
|
{
|
||||||
|
virtual IAsyncFileStream * ToAsyncFile() = 0;
|
||||||
virtual IIOHandle * ToHandle() = 0;
|
virtual IIOHandle * ToHandle() = 0;
|
||||||
|
|
||||||
virtual AuUInt GetBaseAddress() = 0;
|
virtual AuUInt GetBaseAddress() = 0;
|
||||||
@ -22,6 +23,7 @@ namespace Aurora::IO::FS
|
|||||||
|
|
||||||
virtual AuSPtr<IAsyncTransaction> NewAsyncReadTransaction() = 0;
|
virtual AuSPtr<IAsyncTransaction> NewAsyncReadTransaction() = 0;
|
||||||
virtual AuSPtr<IAsyncTransaction> NewAsyncWriteTransaction() = 0;
|
virtual AuSPtr<IAsyncTransaction> NewAsyncWriteTransaction() = 0;
|
||||||
|
virtual AuSPtr<IAsyncTransaction> NewAsyncAnyTransaction() = 0;
|
||||||
|
|
||||||
virtual ISeekingReader * ToStreamSeekingReader() = 0;
|
virtual ISeekingReader * ToStreamSeekingReader() = 0;
|
||||||
virtual ISeekingWriter * ToStreamSeekingWriter() = 0;
|
virtual ISeekingWriter * ToStreamSeekingWriter() = 0;
|
||||||
@ -32,5 +34,6 @@ namespace Aurora::IO::FS
|
|||||||
virtual void Prefetch(AuUInt uOffset,
|
virtual void Prefetch(AuUInt uOffset,
|
||||||
AuUInt uLength) = 0;
|
AuUInt uLength) = 0;
|
||||||
|
|
||||||
|
AURT_ADD_USR_DATA_EXP(this->ToAsyncFile());
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -253,4 +253,18 @@ namespace Aurora::IO::Adapters
|
|||||||
pObject->workers = workers.ValueOr(GetAuxWorkerPool());
|
pObject->workers = workers.ValueOr(GetAuxWorkerPool());
|
||||||
return pObject;
|
return pObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AUKN_SYM AuSPtr<IAsyncTransaction> NewAsyncTransactionFromStreamSeekingPair(const AuSPtr<ISeekingReader> &pStreamReader,
|
||||||
|
const AuSPtr<ISeekingWriter> &pStreamWriter,
|
||||||
|
AuOptional<Aurora::Async::WorkerPId_t> workers)
|
||||||
|
{
|
||||||
|
SysCheckArgNotNull(pStreamWriter, {});
|
||||||
|
SysCheckArgNotNull(pStreamReader, {});
|
||||||
|
auto pObject = AuMakeShared<AsyncReaderWriter>();
|
||||||
|
SysCheckNotNullMemory(pObject, {});
|
||||||
|
pObject->pStreamReaderEx = pStreamReader;
|
||||||
|
pObject->pStreamWriterEx = pStreamWriter;
|
||||||
|
pObject->workers = workers.ValueOr(GetAuxWorkerPool());
|
||||||
|
return pObject;
|
||||||
|
}
|
||||||
}
|
}
|
@ -58,34 +58,85 @@ namespace Aurora::IO::FS
|
|||||||
return AuMakeShared<IO::Buffered::ViewWriter>(this->ToWriteView(), this->pView);
|
return AuMakeShared<IO::Buffered::ViewWriter>(this->ToWriteView(), this->pView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MemoryMappedFile::InitTransactions()
|
||||||
|
{
|
||||||
|
if (AuThreading::InitOnceLocker::TryLock(&this->initOnce))
|
||||||
|
{
|
||||||
|
bool bOk { true };
|
||||||
|
|
||||||
|
if (this->eMode == EFileOpenMode::eReadWrite ||
|
||||||
|
this->eMode == EFileOpenMode::eRead)
|
||||||
|
{
|
||||||
|
auto pReader = AuMakeShared<IO::Buffered::ViewSeekableReader>(this->ToReadViewAlt(), this->pView);
|
||||||
|
|
||||||
|
if (pReader)
|
||||||
|
{
|
||||||
|
auto iBaseOffset = 0 -
|
||||||
|
AuInt64(this->uFileMapOffset) +
|
||||||
|
this->iAdjustStreamOffset;
|
||||||
|
|
||||||
|
pReader->GetBaseOffset() = iBaseOffset;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bOk = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->pStreamReader = pReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->eMode == EFileOpenMode::eReadWrite ||
|
||||||
|
this->eMode == EFileOpenMode::eWrite)
|
||||||
|
{
|
||||||
|
auto pWriter = AuMakeShared<IO::Buffered::ViewSeekableWriter>(this->ToWriteViewAlt(), this->pView);
|
||||||
|
|
||||||
|
if (pWriter)
|
||||||
|
{
|
||||||
|
auto iBaseOffset = 0 -
|
||||||
|
AuInt64(this->uFileMapOffset) +
|
||||||
|
this->iAdjustStreamOffset;
|
||||||
|
|
||||||
|
pWriter->GetBaseOffset() = iBaseOffset;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bOk = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->pStreamWriter = pWriter;
|
||||||
|
}
|
||||||
|
AuThreading::InitOnceLocker::Finish(&this->initOnce, !bOk);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->initOnce.Wait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AuSPtr<IAsyncTransaction> MemoryMappedFile::NewAsyncReadTransaction()
|
AuSPtr<IAsyncTransaction> MemoryMappedFile::NewAsyncReadTransaction()
|
||||||
{
|
{
|
||||||
auto pReader = AuMakeShared<IO::Buffered::ViewSeekableReader>(this->ToReadViewAlt(), this->pView);
|
this->InitTransactions();
|
||||||
SysCheckNotNullMemory(pReader, {});
|
SysCheckNotNullMemory(this->pStreamReader, {});
|
||||||
|
auto pTransaction = Adapters::NewAsyncTransactionFromStreamSeekingReader(this->pStreamReader, {});
|
||||||
auto iBaseOffset = 0 -
|
|
||||||
AuInt64(this->uFileMapOffset) +
|
|
||||||
this->iAdjustStreamOffset;
|
|
||||||
|
|
||||||
pReader->GetBaseOffset() = iBaseOffset;
|
|
||||||
|
|
||||||
auto pTransaction = Adapters::NewAsyncTransactionFromStreamSeekingReader(pReader, {});
|
|
||||||
SysCheckNotNullMemory(pTransaction, {});
|
SysCheckNotNullMemory(pTransaction, {});
|
||||||
return pTransaction;
|
return pTransaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
AuSPtr<IAsyncTransaction> MemoryMappedFile::NewAsyncWriteTransaction()
|
AuSPtr<IAsyncTransaction> MemoryMappedFile::NewAsyncWriteTransaction()
|
||||||
{
|
{
|
||||||
auto pWriter = AuMakeShared<IO::Buffered::ViewSeekableWriter>(this->ToWriteViewAlt(), this->pView);
|
this->InitTransactions();
|
||||||
SysCheckNotNullMemory(pWriter, {});
|
SysCheckNotNullMemory(this->pStreamWriter, {});
|
||||||
|
auto pTransaction = Adapters::NewAsyncTransactionFromStreamSeekingWriter(this->pStreamWriter, {});
|
||||||
|
SysCheckNotNullMemory(pTransaction, {});
|
||||||
|
return pTransaction;
|
||||||
|
}
|
||||||
|
|
||||||
auto iBaseOffset = 0 -
|
AuSPtr<IAsyncTransaction> MemoryMappedFile::NewAsyncAnyTransaction()
|
||||||
AuInt64(this->uFileMapOffset) +
|
{
|
||||||
this->iAdjustStreamOffset;
|
this->InitTransactions();
|
||||||
|
SysCheckNotNullMemory(this->pStreamWriter, {});
|
||||||
pWriter->GetBaseOffset() = iBaseOffset;
|
SysCheckNotNullMemory(this->pStreamReader, {});
|
||||||
|
auto pTransaction = Adapters::NewAsyncTransactionFromStreamSeekingPair(this->pStreamReader, this->pStreamWriter, {});
|
||||||
auto pTransaction = Adapters::NewAsyncTransactionFromStreamSeekingWriter(pWriter, {});
|
|
||||||
SysCheckNotNullMemory(pTransaction, {});
|
SysCheckNotNullMemory(pTransaction, {});
|
||||||
return pTransaction;
|
return pTransaction;
|
||||||
}
|
}
|
||||||
@ -200,6 +251,35 @@ namespace Aurora::IO::FS
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IAsyncFileStream *MemoryMappedFile::ToAsyncFile()
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
AuSPtr<IAsyncTransaction> MemoryMappedFile::NewTransaction()
|
||||||
|
{
|
||||||
|
return this->NewAsyncAnyTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MemoryMappedFile::BlockingTruncate(AuUInt64 length)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MemoryMappedFile::BlockingRead(AuUInt64 offset, const Memory::MemoryViewStreamWrite ¶meters)
|
||||||
|
{
|
||||||
|
this->InitTransactions();
|
||||||
|
SysCheckNotNullMemory(this->pStreamReader, {});
|
||||||
|
return this->pStreamReader->ArbitraryRead(offset, parameters) == EStreamError::eErrorNone;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MemoryMappedFile::BlockingWrite(AuUInt64 offset, const Memory::MemoryViewStreamRead ¶meters)
|
||||||
|
{
|
||||||
|
this->InitTransactions();
|
||||||
|
SysCheckNotNullMemory(this->pStreamWriter, {});
|
||||||
|
return this->pStreamWriter->ArbitraryWrite(offset, parameters) == EStreamError::eErrorNone;
|
||||||
|
}
|
||||||
|
|
||||||
bool MemoryMappedFile::Init(EFileOpenMode eMode,
|
bool MemoryMappedFile::Init(EFileOpenMode eMode,
|
||||||
AuUInt64 uFileMapOffset,
|
AuUInt64 uFileMapOffset,
|
||||||
AuUInt64 uFileMapLength,
|
AuUInt64 uFileMapLength,
|
||||||
@ -213,7 +293,7 @@ namespace Aurora::IO::FS
|
|||||||
uFileMapLength = pHandle->GetFileLength();
|
uFileMapLength = pHandle->GetFileLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->eMode = eMode;
|
||||||
this->uFileMapLength = uFileMapLength;
|
this->uFileMapLength = uFileMapLength;
|
||||||
this->uFileMapOffset = uFileMapOffset;
|
this->uFileMapOffset = uFileMapOffset;
|
||||||
this->iAdjustStreamOffset = iAdjustStreamOffset;
|
this->iAdjustStreamOffset = iAdjustStreamOffset;
|
||||||
|
@ -9,9 +9,10 @@
|
|||||||
|
|
||||||
namespace Aurora::IO::FS
|
namespace Aurora::IO::FS
|
||||||
{
|
{
|
||||||
struct MemoryMappedFile : IMemoryMappedFile
|
struct MemoryMappedFile : IMemoryMappedFile, IAsyncFileStream
|
||||||
{
|
{
|
||||||
virtual IIOHandle * ToHandle() override;
|
virtual IIOHandle * ToHandle() override;
|
||||||
|
virtual IAsyncFileStream * ToAsyncFile() override;
|
||||||
|
|
||||||
virtual AuUInt GetBaseAddress() override;
|
virtual AuUInt GetBaseAddress() override;
|
||||||
virtual AuUInt GetEndAddress() override;
|
virtual AuUInt GetEndAddress() override;
|
||||||
@ -20,8 +21,11 @@ namespace Aurora::IO::FS
|
|||||||
virtual AuSPtr<IStreamReader> NewStreamReader() override;
|
virtual AuSPtr<IStreamReader> NewStreamReader() override;
|
||||||
virtual AuSPtr<IStreamWriter> NewStreamWriter() override;
|
virtual AuSPtr<IStreamWriter> NewStreamWriter() override;
|
||||||
|
|
||||||
|
void InitTransactions();
|
||||||
|
|
||||||
virtual AuSPtr<IAsyncTransaction> NewAsyncReadTransaction() override;
|
virtual AuSPtr<IAsyncTransaction> NewAsyncReadTransaction() override;
|
||||||
virtual AuSPtr<IAsyncTransaction> NewAsyncWriteTransaction() override;
|
virtual AuSPtr<IAsyncTransaction> NewAsyncWriteTransaction() override;
|
||||||
|
virtual AuSPtr<IAsyncTransaction> NewAsyncAnyTransaction() override;
|
||||||
|
|
||||||
virtual ISeekingReader * ToStreamSeekingReader() override;
|
virtual ISeekingReader * ToStreamSeekingReader() override;
|
||||||
virtual ISeekingWriter * ToStreamSeekingWriter() override;
|
virtual ISeekingWriter * ToStreamSeekingWriter() override;
|
||||||
@ -36,6 +40,13 @@ namespace Aurora::IO::FS
|
|||||||
|
|
||||||
virtual void Prefetch(AuUInt uOffset,
|
virtual void Prefetch(AuUInt uOffset,
|
||||||
AuUInt uLength) override;
|
AuUInt uLength) override;
|
||||||
|
|
||||||
|
AuSPtr<IAsyncTransaction> NewTransaction() override;
|
||||||
|
|
||||||
|
bool BlockingTruncate(AuUInt64 length) override;
|
||||||
|
bool BlockingRead(AuUInt64 offset, const Memory::MemoryViewStreamWrite ¶meters) override;
|
||||||
|
bool BlockingWrite(AuUInt64 offset, const Memory::MemoryViewStreamRead ¶meters) override;
|
||||||
|
|
||||||
bool Init(EFileOpenMode eMode,
|
bool Init(EFileOpenMode eMode,
|
||||||
AuUInt64 uFileMapOffset,
|
AuUInt64 uFileMapOffset,
|
||||||
AuUInt64 uFileMapLength,
|
AuUInt64 uFileMapLength,
|
||||||
@ -46,9 +57,13 @@ namespace Aurora::IO::FS
|
|||||||
AuSPtr<AuIO::IIOHandle> pHandleShared;
|
AuSPtr<AuIO::IIOHandle> pHandleShared;
|
||||||
AuSPtr<AuProcess::IProcessSectionMapView> pView;
|
AuSPtr<AuProcess::IProcessSectionMapView> pView;
|
||||||
AuUInt64 uFileMapLength;
|
AuUInt64 uFileMapLength;
|
||||||
|
EFileOpenMode eMode;
|
||||||
AuUInt64 uFileMapOffset;
|
AuUInt64 uFileMapOffset;
|
||||||
AuInt64 iAdjustStreamOffset;
|
AuInt64 iAdjustStreamOffset;
|
||||||
AuOptional<IO::Buffered::ViewSeekableWriter> optSeekableWriter;
|
AuOptional<IO::Buffered::ViewSeekableWriter> optSeekableWriter;
|
||||||
AuOptional<IO::Buffered::ViewSeekableReader> optSeekableReader;
|
AuOptional<IO::Buffered::ViewSeekableReader> optSeekableReader;
|
||||||
|
AuInitOnce initOnce;
|
||||||
|
AuSPtr<IO::Buffered::ViewSeekableReader> pStreamReader;
|
||||||
|
AuSPtr<IO::Buffered::ViewSeekableWriter> pStreamWriter;
|
||||||
};
|
};
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user