Second Life source analysis (43) virtual file system thread

Source: Internet
Author: User
Tags message queue thread class
Because Second Life is a 3D display software, it needs to constantly download a large amount of data from the server, such as texture pictures, different characters are using different texture pictures to achieve different clothing appearance. When these roles are displayed, the texture pictures downloaded from the server are used. If you show more personas, such as 30 people, these textures will need to be saved to disk. So how to save it to disk. Saving to disk requires a good file system to save and read the data. Reading and writing to disk is a relatively slow task, so you need to use a thread to implement it. It is also sometimes not necessary to read and write files in a timely manner, so that threads can wait until the CPU is idle to do these things. The   Llvfsthread class is inherited from the Llqueuedthread class, so that llvfsthread becomes the message loop processing class. Only need to continuously add the request to the message queue, and then implement the message processing function, the corresponding function is implemented. #001  //static #002  void llvfsthread::initclass (bool local_is_threaded) #003  {#004         Llassert (slocal = NULL); #005        slocal = new Llvfsthread (local_is_threaded); The virtual file system thread class is &nbsp on the top of #006.     #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  {  Get handle handles. #005        handle_t handle = Generatehandle (); #006     Get the execution priority of this request. #007        priority = Llmax (priority, (U32) priority_low); All reads are at least Priority_low   create read data request messages. #008        request* req = new Request (handle, priority, flags, File_read, VFS, file_id, File_type , #009                                                       buffer, offset, NumBytes); #010     Add this message to the message queue. #011       BOOL res = addrequest (req); #012        if (!res) #013        {#014                llerrs << "Llvfsthread::read called after Llvfsthread:: Cleanupclass () "<< Llendl; #015               req->deleterequest (); #016               handle = Nullhandle (); #017       } #018   #019        return handle; #020 &nbsp}   The virtual file system needs to implement the file data in the read, the function Llvfsthread::read above is to realize this function.   #001  s32 llvfsthread::readimmediate (llvfs* vfs, const lluuid &file_id, const llassettype::etype File_ Type, #002                                                      u8* buffer, S32 offset, S32 numbytes) #003  {  get thread handle. #004        handle_t handle = Generatehandle (); #005     Create a request to read data immediately, the main priority is not the same. #006        request* req = new Request (handle, priority_immediate, 0, File_read, VFS, FILE_ID, fil E_type, #007                                                       buffer, offset, NumBytes); #008          Add requests to message queues. #009        S32 res = addrequest (req)? 1:0; #010        if (res = 0) #011        {#012               llerrs << "Llvfsthread::read called after Llvfsthread:: Cleanupclass () "<< Llendl; #013               req->deleterequest (); #014       } #015        else #016        {# 017              llverify (Waitforresult (handle, False ) = = true); #018               res = Req->getbytesread (); #019               completerequest (handle); #020       } #021        return res; #022 &nbsp}   The function above implements the requirement to read data immediately.   #001  llvfsthread::handle_t llvfsthread::write (llvfs* vfs, const lluuid &file_id, const llassettype:: EType File_type, #002   &NBSP;&NBSP;&NBSP;&NBSP;&NBsp;                                                                   u8* buffer, S32 #003  offset, S32 numbytes, U32 flags ) #004  {  Get the thread handle. #005        handle_t handle = Generatehandle (); #006     To add a request to write file data to a virtual file system. #007        request* req = new Request (handle, 0, flags, File_write, VFS, file_id, File_type, #008                                                        buffer, offset, numbytes); #009     Add message requests to Message Queuing. #010        BOOL res = addrequest (req); #011        if (!res) #012        {#013                llerrs << "Llvfsthread::read called after Llvfsthread:: Cleanupclass () "<< Llendl; #014               req->deleterequest (); #015               handle = Nullhandle (); #016       } #017        #018        return Handle #019 &nbsp}   The above function implements a message request that writes data to a virtual file system. Then there is the Llvfsthread::writeimmediate function, which implements the request to write data to the virtual file system immediately. With four functions, you can add requests to read data and write data to the virtual file system, and how are these requests handled? I'll take you to understand it next time.  

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.