// Reads imagesize from the header, updates timestamp S32 LLTextureCache::getHeaderCacheEntry(const LLUUID& id, S32& imagesize) { LLMutexLock lock(&mHeaderMutex); Entry entry; S32 idx = openAndReadEntry(id, entry, false); if (idx >= 0) { imagesize = entry.mImageSize; writeEntryAndClose(idx, entry); // updates time } return idx; }
bool LLTextureCache::updateTextureEntryList(const LLUUID& id, S32 bodysize) { bool res = false; bool purge = false; { mHeaderMutex.lock(); size_map_t::iterator iter1 = mTexturesSizeMap.find(id); if (iter1 == mTexturesSizeMap.end() || iter1->second < bodysize) { llassert_always(bodysize > 0); S32 oldbodysize = 0; if (iter1 != mTexturesSizeMap.end()) { oldbodysize = iter1->second; } Entry entry; S32 idx = openAndReadEntry(id, entry, false); if (idx < 0) { // TODO: change to llwarns llerrs << "Failed to open entry: " << id << llendl; mHeaderMutex.unlock(); removeFromCache(id); return false; } else if (oldbodysize != entry.mBodySize) { // TODO: change to llwarns llerrs << "Entry mismatch in mTextureSizeMap / mHeaderIDMap" << " idx=" << idx << " oldsize=" << oldbodysize << " entrysize=" << entry.mBodySize << llendl; } entry.mBodySize = bodysize; writeEntryAndClose(idx, entry); mTexturesSizeTotal -= oldbodysize; mTexturesSizeTotal += bodysize; if (mTexturesSizeTotal > sCacheMaxTexturesSize) { purge = true; } res = true; } } if (purge) { mDoPurge = TRUE; } mHeaderMutex.unlock(); return res; }
bool LLTextureCache::removeHeaderCacheEntry(const LLUUID& id) { if (!mReadOnly) { Entry entry; S32 idx = openAndReadEntry(id, entry, false); if (idx >= 0) { entry.mImageSize = -1; entry.mBodySize = 0; writeEntryAndClose(idx, entry); mFreeList.insert(idx); mHeaderIDMap.erase(id); mTexturesSizeMap.erase(id); return true; } } return false; }
// Writes imagesize to the header, updates timestamp S32 LLTextureCache::setHeaderCacheEntry(const LLUUID& id, S32 imagesize) { mHeaderMutex.lock(); llassert_always(imagesize >= 0); Entry entry; S32 idx = openAndReadEntry(id, entry, true); if (idx >= 0) { entry.mImageSize = imagesize; writeEntryAndClose(idx, entry); mHeaderMutex.unlock(); } else // retry { mHeaderMutex.unlock(); readHeaderCache(); // We couldn't write an entry, so refresh the LRU mHeaderMutex.lock(); llassert_always(!mLRU.empty() || mHeaderEntriesInfo.mEntries < sCacheMaxEntries); mHeaderMutex.unlock(); idx = setHeaderCacheEntry(id, imagesize); // assert above ensures no inf. recursion } return idx; }