// MAIN thread LLQueuedThread::handle_t LLQueuedThread::generateHandle() { lockData(); while ((mNextHandle == nullHandle()) || (mRequestHash.find(mNextHandle))) { mNextHandle++; } unlockData(); return mNextHandle++; }
// MAIN thread LLQueuedThread::QueuedRequest* LLQueuedThread::getRequest(handle_t handle) { if (handle == nullHandle()) { return 0; } lockData(); QueuedRequest* res = (QueuedRequest*)mRequestHash.find(handle); unlockData(); return res; }
LLWorkerThread::handle_t LLWorkerThread::addWorkRequest(LLWorkerClass* workerclass, S32 param, U32 priority) { handle_t handle = generateHandle(); WorkRequest* req = new WorkRequest(handle, priority, workerclass, param); bool res = addRequest(req); if (!res) { llwarns << "add called after LLWorkerThread::cleanupClass()" << llendl; req->deleteRequest(); handle = nullHandle(); } return handle; }
LLVFSThread::handle_t LLVFSThread::write(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type, U8* buffer, S32 offset, S32 numbytes, U32 flags) { handle_t handle = generateHandle(); Request* req = new Request(handle, 0, flags, FILE_WRITE, vfs, file_id, file_type, buffer, offset, numbytes); bool res = addRequest(req); if (!res) { LL_ERRS() << "LLVFSThread::read called after LLVFSThread::cleanupClass()" << LL_ENDL; req->deleteRequest(); handle = nullHandle(); } return handle; }
LLVFSThread::handle_t LLVFSThread::read(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type, U8* buffer, S32 offset, S32 numbytes, U32 priority, U32 flags) { handle_t handle = generateHandle(); priority = llmax(priority, (U32)PRIORITY_LOW); // All reads are at least PRIORITY_LOW Request* req = new Request(handle, priority, flags, FILE_READ, vfs, file_id, file_type, buffer, offset, numbytes); bool res = addRequest(req); if (!res) { LL_ERRS() << "LLVFSThread::read called after LLVFSThread::cleanupClass()" << LL_ENDL; req->deleteRequest(); handle = nullHandle(); } return handle; }
// MAIN thread bool LLQueuedThread::waitForResult(LLQueuedThread::handle_t handle, bool auto_complete) { llassert (handle != nullHandle()); bool res = false; bool waspaused = isPaused(); bool done = false; while(!done) { update(0); // unpauses lockData(); QueuedRequest* req = (QueuedRequest*)mRequestHash.find(handle); if (!req) { done = true; // request does not exist } else if (req->getStatus() == STATUS_COMPLETE && !(req->getFlags() & FLAG_LOCKED)) { res = true; if (auto_complete) { mRequestHash.erase(handle); req->deleteRequest(); // check(); } done = true; } unlockData(); if (!done && mThreaded) { yield(); } } if (waspaused) { pause(); } return res; }
mRequestQueue.insert(req); mRequestHash.insert(req); #if _DEBUG // llinfos << llformat("LLQueuedThread::Added req [%08d]",handle) << llendl; #endif unlockData(); incQueue(); return true; } // MAIN thread bool LLQueuedThread::waitForResult(LLQueuedThread::handle_t handle, bool auto_complete) { llassert (handle != nullHandle()) bool res = false; bool waspaused = isPaused(); bool done = false; while(!done) { update(0); // unpauses lockData(); QueuedRequest* req = (QueuedRequest*)mRequestHash.find(handle); if (!req) { done = true; // request does not exist } else if (req->getStatus() == STATUS_COMPLETE) { res = true;