Second Life Source Code Analysis (forty-three) virtual file system thread

Source: Internet
Author: User
Tags message queue thread class

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.