Ark Server API (ASA) - Wiki
|
#include <PreloadableFile.h>
Classes | |
struct | FSavedReadCompleteArguments |
Public Types | |
enum | Flags { None = 0x0 , ModeBits = 0x1 , PreloadHandle = 0x0 , PreloadBytes = 0x1 , Prime = 0x2 } |
enum | { DefaultPrimeSize = 1024 , DefaultPageSize = 64*1024 } |
typedef TUniqueFunction< FArchive *()> | FCreateArchive |
typedef TUniqueFunction< IAsyncReadFileHandle *()> | FCreateAsyncArchive |
Protected Member Functions | |
void | InitializeInternalAsync (FCreateArchive &&InCreateArchiveFunction, FCreateAsyncArchive &&InCreateAsyncArchiveFunction, uint32 InFlags, int64 PrimeSize) |
void | InitializeInternal (FCreateArchive &&InCreateArchiveFunction, FCreateAsyncArchive &&InCreateAsyncArchiveFunction, uint32 Flags, int64 PrimeSize) |
void | PausePreload () |
void | ResumePreload () |
bool | ResumePreloadNonRecursive () |
void | OnReadComplete (bool bCanceled, IAsyncReadRequest *ReadRequest) |
void | FreeRetiredRequests () |
void | SerializeSynchronously (void *V, int64 Length) |
Protected Member Functions inherited from FArchive | |
void | SetShouldSkipCompilingAssets (bool Enabled) |
Protected Attributes | |
FString | ArchiveName |
int64 | Pos = 0 |
int64 | Size = -1 |
FEvent * | PendingAsyncComplete = nullptr |
TAtomic< bool > | bInitialized |
TAtomic< bool > | bIsPreloading |
TAtomic< bool > | bIsPreloadingPaused |
uint8 * | CacheBytes = nullptr |
TAtomic< int64 > | CacheEnd |
TUniquePtr< IAsyncReadFileHandle > | AsynchronousHandle |
TUniquePtr< FArchive > | SynchronousArchive |
TArray< IAsyncReadRequest * > | RetiredRequests |
int64 | PageSize = DefaultPageSize |
FCriticalSection | PreloadLock |
bool | bReadCompleteWasCalledInline = false |
bool | bIsInlineReadComplete = false |
struct FPreloadableArchive::FSavedReadCompleteArguments | SavedReadCompleteArguments |
Friends | |
class | FPreloadableFileProxy |
A read-only archive that adds support for asynchronous preloading and priming to an inner archive.
This class supports two mutually-exclusive modes: PreloadBytes: An asynchronous inner archive is opened using the passed-in CreateAsyncArchive function; this call is made asynchronously on a TaskGraph thread. The size is read during initialization. After initialization, when StartPreload is called, an array of bytes equal in size to the inner archive's size is allocated, and an asynchronous ReadRequest is sent to the IAsyncReadFileHandle to read the first <PageSize> bytes of the file. Upon completion of each in-flight ReadRequest, another asynchronous ReadRequest is issued, until the entire file has been read. If serialize functions are called beyond the bytes of the file that have been cached so far, they requests are satisfied by synchronous reads.
Activate this mode by passing an FCreateArchive to InitializeAsync. PreloadHandle: A synchronous inner archive is opened using the passed-in CreateArchive function; this call is made asynchronously on a TaskGraph thread. Optionally, a precache request is sent to the inner archive for the first <PrimeSize> bytes; this call is also made asynchronously. The created and primed lower-level FArchive can then be detached from this class and handed off to a new owner.
Activate this mode by passing an FCreateAsyncArchive and (optionally, for the precache request) Flags::Prime to InitializeAsync.
This class is not threadsafe. The public interface can be used at the same time as internal asynchronous tasks are executing, but the public interface can not be used from multiple threads at once.
Definition at line 49 of file PreloadableFile.h.
Definition at line 52 of file PreloadableFile.h.
typedef TUniqueFunction<IAsyncReadFileHandle* ()> FPreloadableArchive::FCreateAsyncArchive |
Definition at line 53 of file PreloadableFile.h.
Enumerator | |
---|---|
DefaultPrimeSize | |
DefaultPageSize |
Definition at line 67 of file PreloadableFile.h.
Enumerator | |
---|---|
None | |
ModeBits | |
PreloadHandle | |
PreloadBytes | |
Prime |
Definition at line 55 of file PreloadableFile.h.
FPreloadableArchive::FPreloadableArchive | ( | FStringView | ArchiveName | ) |
|
virtual |
bool FPreloadableArchive::AllocateCache | ( | ) |
When in PreloadBytes mode, allocate if necessary the memory for the preloaded bytes. Return whether the memory is now allocated.
Attempts to close and finalize any handles used for backing data storage, returns true if it succeeded.
Reimplemented from FArchive.
FArchive * FPreloadableArchive::DetachLowerLevel | ( | ) |
Return the LowerLevel FArchive if it has been allocated. May return null, even if the FPreloadableFile is currently active. If return value is non-null, caller is responsible for deleting it.
|
protected |
Returns the name of the Archive. Useful for getting the name of the package a struct or object is in when a loading error occurs.
This is overridden for the specific Archive Types
Reimplemented from FArchive.
void FPreloadableArchive::InitializeAsync | ( | FCreateArchive && | InCreateArchiveFunction, |
uint32 | InFlags = Flags::None, | ||
int64 | PrimeSize = DefaultPrimeSize ) |
Initialize the FPreloadableFile asynchronously, performing FileOpen operations on another thread. Use IsInitialized or WaitForInitialization to check progress.
void FPreloadableArchive::InitializeAsync | ( | FCreateAsyncArchive && | InCreateAsyncArchiveFunction, |
uint32 | InFlags = Flags::None, | ||
int64 | PrimeSize = DefaultPrimeSize ) |
|
protected |
Helper function for InitializeAsync, called from a TaskGraph thread.
|
protected |
Helper function for InitializeAsync, sets up the asynchronous call to InitializeInternal
bool FPreloadableArchive::IsCacheAllocated | ( | ) | const |
Return whether the cache is currently allocated.
bool FPreloadableArchive::IsInitialized | ( | ) | const |
Return whether InitializeAsync has completed. If Close is called, state returns to false until the next call to InitializeAsync.
bool FPreloadableArchive::IsPreloading | ( | ) | const |
Return whether preloading is in progress. Value may not be up to date since asynchronous work might complete in a race condition.
|
protected |
|
protected |
void FPreloadableArchive::ReleaseCache | ( | ) |
Free all memory used by the cache or for preloading (calling StopPreload if necessary).
|
protected |
|
protected |
Attempts to set the current offset into backing data storage, this will do nothing if there is no storage.
Reimplemented from FArchive.
Reimplemented from FArchive.
Set the PageSize used read requests made to the LowerLevel Archive in PreloadBytes mode when reading bytes into the In-Memory cache. Invalid to set after Initialization; PageSize must be constant during use.
bool FPreloadableArchive::StartPreload | ( | ) |
When in PreloadBytes mode, if not already preloading, allocate if necessary the memory for the preloaded bytes and start the chain of asynchronous ReadRequests for the bytes. Returns whether preloading is now active.
void FPreloadableArchive::StopPreload | ( | ) |
Cancel any current asynchronous ReadRequests and wait for the asynchronous work to exit.
Returns the current location within the backing data storage, which can possibly be passed to Seek later to restore a read/write location. If this returns -1, there is no backing data storage and Seek will not function.
Reimplemented from FArchive.
Return the size of the file, or -1 if the file does not exist. This is also the amount of memory that will be allocated by AllocateCache.
Reimplemented from FArchive.
void FPreloadableArchive::WaitForInitialization | ( | ) | const |
Wait for InitializeAsync to complete if it is running, otherwise return immediately.
Definition at line 192 of file PreloadableFile.h.
|
protected |
Definition at line 127 of file PreloadableFile.h.
|
protected |
The handle used for PreloadBytes mode, to fulfull ReadReqeusts.
Definition at line 152 of file PreloadableFile.h.
Threadsafe variable that returns true only after all asynchronous initialization is complete. Is also reset to false when public-interface users call Close().
Definition at line 136 of file PreloadableFile.h.
Set to true during the ReadRequest call to allow us to detect if OnReadComplete is called inline on the same thread from ReadRequest.
Definition at line 169 of file PreloadableFile.h.
Threadsafe variable that is true only during the period between initialization until Preloading stops (either due to EOF reached or due to Serialize turning it off.
Definition at line 138 of file PreloadableFile.h.
Variable that is set to true from the public interface thread to signal that (temporarily) no further ReadRequests should be sent when the currently active one completes.
Definition at line 140 of file PreloadableFile.h.
Set to true if OnReadComplete is called inline on the same thread from ReadRequest; we need special handling for this case.
Definition at line 167 of file PreloadableFile.h.
An array of bytes of size Size. Non-null only in PreloadBytes mode and in-between calls to AllocateCache/ReleaseCache.
Definition at line 143 of file PreloadableFile.h.
Number of bytes in CacheBytes that have already been read. This is used in Serialize to check which bytes are available and in preloading to know for which bytes to issue a read request. This variable is read-only threadsafe. It is guaranteed to be written only after the bytes in CacheBytes have finished writing, and it is guaranteed to be written before bIsPreloading is written. It is not fully threadsafe; threads that need to write to CacheEnd need to do their Read/Write within the PreloadLock CriticalSection.
Definition at line 149 of file PreloadableFile.h.
|
protected |
The number of bytes requested from the AsynchronousHandle in each ReadRequest. Larger values have slightly faster results due to per-call overhead, but add greater latency to Serialize calls that read past the end of the cache.
Definition at line 162 of file PreloadableFile.h.
An Event used for synchronization with asynchronous tasks - InitializingAsync or receiving ReadRequests from the AsynchronousHandle.
Definition at line 134 of file PreloadableFile.h.
|
protected |
The Offset into the file or preloaded bytes that will be used in the next call to Serialize.
Definition at line 129 of file PreloadableFile.h.
|
protected |
CriticalSection used to synchronize access to the CacheBytes.
Definition at line 165 of file PreloadableFile.h.
|
protected |
ReadRequests that have completed but we have not yet deleted.
Definition at line 160 of file PreloadableFile.h.
|
protected |
|
protected |
The number of bytes in the file.
Definition at line 131 of file PreloadableFile.h.
|
protected |
The archive used in PreloadHandle mode or to service Serialize requests that are beyond CacheEnd when in PreloadBytes mode.
Definition at line 154 of file PreloadableFile.h.