Because the Second Life is a 3D display software, it needs to constantly download a large amount of data from the server, such as texture images, different roles use different texture images for different clothing appearances. When these roles are displayed, the texture image downloaded from the server is used. If many characters are displayed, such as 30, these texture images need to be saved to the disk. So how to save it to the disk? A good file system is required to save and read data to the disk. Reading and writing a disk is slow, so you need to use a thread to implement it. Sometimes, reading and writing files does not require timely actions, so that the thread can wait until the CPU is idle.
The LLVFSThread class inherits the LLQueuedThread class, so that LLVFSThread becomes a message loop processing class. You only need to add requests to the message queue and then implement the message processing function to implement the corresponding functions.
#001 // static
#002 void LLVFSThread: initClass (bool local_is_threaded)
#003 {
#004 llassert (sLocal = NULL );
#005 sLocal = new LLVFSThread (local_is_threaded );
#006}
The above implements the Virtual File System Thread class.
#001 LLVFSThread: handle_t LLVFSThread: read (LLVFS * vfs, const LLUUID & file_id, const LLAssetType: EType file_type,
#002 U8 * buffer, S32
#003 offset, S32 numbytes, U32 priority, U32 flags)
#004 {
Obtain the processing handle.
#005 handle_t handle = generateHandle ();
#006
Obtain the execution priority of the request.
#007 priority = llmax (priority, (U32) PRIORITY_LOW); // All reads are at least PRIORITY_LOW
Create a data read request message.
#008 Request * req = new Request (handle, priority, flags, FILE_READ, vfs, file_id, file_type,
#009 buffer, offset, numbytes );
#010
Add the message to the message queue.
#011 bool res = addReq