aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview')
-rw-r--r--linden/indra/newview/lltexturecache.cpp54
-rw-r--r--linden/indra/newview/lltexturecache.h1
2 files changed, 33 insertions, 22 deletions
diff --git a/linden/indra/newview/lltexturecache.cpp b/linden/indra/newview/lltexturecache.cpp
index a9b7f81..a1a9a39 100644
--- a/linden/indra/newview/lltexturecache.cpp
+++ b/linden/indra/newview/lltexturecache.cpp
@@ -1172,7 +1172,7 @@ void LLTextureCache::readHeaderCache()
1172 U32 empty_entries = 0; 1172 U32 empty_entries = 0;
1173 typedef std::pair<U32, LLUUID> lru_data_t; 1173 typedef std::pair<U32, LLUUID> lru_data_t;
1174 std::set<lru_data_t> lru; 1174 std::set<lru_data_t> lru;
1175 std::vector<LLUUID> purge_list; 1175 std::set<LLUUID> purge_list;
1176 for (U32 i=0; i<num_entries; i++) 1176 for (U32 i=0; i<num_entries; i++)
1177 { 1177 {
1178 Entry& entry = entries[i]; 1178 Entry& entry = entries[i];
@@ -1191,27 +1191,23 @@ void LLTextureCache::readHeaderCache()
1191 { 1191 {
1192 // Shouldn't happen, failsafe only 1192 // Shouldn't happen, failsafe only
1193 llwarns << "Bad entry: " << i << ": " << entry.mID << ": BodySize: " << entry.mBodySize << llendl; 1193 llwarns << "Bad entry: " << i << ": " << entry.mID << ": BodySize: " << entry.mBodySize << llendl;
1194 purge_list.push_back(id); 1194 purge_list.insert(id);
1195 } 1195 }
1196 } 1196 }
1197 } 1197 }
1198 } 1198 }
1199 if (num_entries > sCacheMaxEntries) 1199 if (num_entries - empty_entries > sCacheMaxEntries)
1200 { 1200 {
1201 // Special case: cache size was reduced, need to remove entries 1201 // Special case: cache size was reduced, need to remove entries
1202 // Note: After we prune entries, we will call this again and create the LRU 1202 // Note: After we prune entries, we will call this again and create the LRU
1203 U32 entries_to_purge = (num_entries-empty_entries) - sCacheMaxEntries; 1203 U32 entries_to_purge = (num_entries - empty_entries) - sCacheMaxEntries;
1204 llinfos << "Texture Cache Entries: " << num_entries << " Max: " << sCacheMaxEntries << " Empty: " << empty_entries << " Purging: " << entries_to_purge << llendl; 1204 llinfos << "Texture Cache Entries: " << num_entries << " Max: " << sCacheMaxEntries << " Empty: " << empty_entries << " Purging: " << entries_to_purge << llendl;
1205 if (entries_to_purge > 0) 1205 // We can exit the following loop with the given condition, since if we'd reach the end of the lru set we'd have:
1206 // purge_list.size() = lru.size() = num_entries - empty_entries = entries_to_purge + sCacheMaxEntries >= entries_to_purge
1207 for (std::set<lru_data_t>::iterator iter = lru.begin(); purge_list.size() < entries_to_purge; ++iter)
1206 { 1208 {
1207 for (std::set<lru_data_t>::iterator iter = lru.begin(); iter != lru.end(); ++iter) 1209 purge_list.insert(iter->second);
1208 {
1209 purge_list.push_back(iter->second);
1210 if (purge_list.size() >= entries_to_purge)
1211 break;
1212 }
1213 } 1210 }
1214 llassert_always(purge_list.size() >= entries_to_purge);
1215 } 1211 }
1216 else 1212 else
1217 { 1213 {
@@ -1227,11 +1223,9 @@ void LLTextureCache::readHeaderCache()
1227 1223
1228 if (purge_list.size() > 0) 1224 if (purge_list.size() > 0)
1229 { 1225 {
1230 for (std::vector<LLUUID>::iterator iter = purge_list.begin(); iter != purge_list.end(); ++iter) 1226 for (std::set<LLUUID>::iterator iter = purge_list.begin(); iter != purge_list.end(); ++iter)
1231 { 1227 {
1232 mHeaderMutex.unlock(); 1228 removeFromCacheLocked(*iter);
1233 removeFromCache(*iter);
1234 mHeaderMutex.lock();
1235 } 1229 }
1236 // If we removed any entries, we need to rebuild the entries list, 1230 // If we removed any entries, we need to rebuild the entries list,
1237 // write the header, and call this again 1231 // write the header, and call this again
@@ -1250,7 +1244,7 @@ void LLTextureCache::readHeaderCache()
1250 writeEntriesAndClose(new_entries); 1244 writeEntriesAndClose(new_entries);
1251 mHeaderMutex.unlock(); // unlock the mutex before calling again 1245 mHeaderMutex.unlock(); // unlock the mutex before calling again
1252 readHeaderCache(); // repeat with new entries file 1246 readHeaderCache(); // repeat with new entries file
1253 mHeaderMutex.lock(); 1247 return;
1254 } 1248 }
1255 else 1249 else
1256 { 1250 {
@@ -1345,7 +1339,7 @@ void LLTextureCache::purgeTextures(bool validate)
1345 if (validate) 1339 if (validate)
1346 { 1340 {
1347 validate_idx = gSavedSettings.getU32("CacheValidateCounter"); 1341 validate_idx = gSavedSettings.getU32("CacheValidateCounter");
1348 U32 next_idx = (++validate_idx) % 256; 1342 U32 next_idx = (validate_idx + 1) % 256;
1349 gSavedSettings.setU32("CacheValidateCounter", next_idx); 1343 gSavedSettings.setU32("CacheValidateCounter", next_idx);
1350 LL_DEBUGS("TextureCache") << "TEXTURE CACHE: Validating: " << validate_idx << LL_ENDL; 1344 LL_DEBUGS("TextureCache") << "TEXTURE CACHE: Validating: " << validate_idx << LL_ENDL;
1351 } 1345 }
@@ -1388,7 +1382,15 @@ void LLTextureCache::purgeTextures(bool validate)
1388 { 1382 {
1389 purge_count++; 1383 purge_count++;
1390 LL_DEBUGS("TextureCache") << "PURGING: " << filename << LL_ENDL; 1384 LL_DEBUGS("TextureCache") << "PURGING: " << filename << LL_ENDL;
1391 LLAPRFile::remove(filename); 1385 if (entries[idx].mBodySize > 0)
1386 {
1387 LLAPRFile::remove(filename);
1388 }
1389 else if (LLAPRFile::isExist(filename)) // Sanity check. Shouldn't exist.
1390 {
1391 LL_WARNS("TextureCache") << "Entry has zero body size but existing " << filename << ". Deleting file too..." << LL_ENDL;
1392 LLAPRFile::remove(filename);
1393 }
1392 cache_size -= entries[idx].mBodySize; 1394 cache_size -= entries[idx].mBodySize;
1393 mTexturesSizeTotal -= entries[idx].mBodySize; 1395 mTexturesSizeTotal -= entries[idx].mBodySize;
1394 entries[idx].mBodySize = 0; 1396 entries[idx].mBodySize = 0;
@@ -1615,7 +1617,6 @@ bool LLTextureCache::removeHeaderCacheEntry(const LLUUID& id)
1615{ 1617{
1616 if (!mReadOnly) 1618 if (!mReadOnly)
1617 { 1619 {
1618 LLMutexLock lock(&mHeaderMutex);
1619 Entry entry; 1620 Entry entry;
1620 S32 idx = openAndReadEntry(id, entry, false); 1621 S32 idx = openAndReadEntry(id, entry, false);
1621 if (idx >= 0) 1622 if (idx >= 0)
@@ -1632,17 +1633,26 @@ bool LLTextureCache::removeHeaderCacheEntry(const LLUUID& id)
1632 return false; 1633 return false;
1633} 1634}
1634 1635
1635void LLTextureCache::removeFromCache(const LLUUID& id) 1636void LLTextureCache::removeFromCacheLocked(const LLUUID& id)
1636{ 1637{
1637 //llwarns << "Removing texture from cache: " << id << llendl; 1638 //llwarns << "Removing texture from cache: " << id << llendl;
1638 if (!mReadOnly) 1639 if (!mReadOnly)
1639 { 1640 {
1640 removeHeaderCacheEntry(id); 1641 removeHeaderCacheEntry(id);
1641 LLMutexLock lock(&mHeaderMutex);
1642 LLAPRFile::remove(getTextureFileName(id)); 1642 LLAPRFile::remove(getTextureFileName(id));
1643 } 1643 }
1644} 1644}
1645 1645
1646void LLTextureCache::removeFromCache(const LLUUID& id)
1647{
1648 //llwarns << "Removing texture from cache: " << id << llendl;
1649 if (!mReadOnly)
1650 {
1651 LLMutexLock lock(&mHeaderMutex);
1652 LLTextureCache::removeFromCacheLocked(id);
1653 }
1654}
1655
1646////////////////////////////////////////////////////////////////////////////// 1656//////////////////////////////////////////////////////////////////////////////
1647 1657
1648LLTextureCache::ReadResponder::ReadResponder() 1658LLTextureCache::ReadResponder::ReadResponder()
diff --git a/linden/indra/newview/lltexturecache.h b/linden/indra/newview/lltexturecache.h
index 45804c2..c859b9a 100644
--- a/linden/indra/newview/lltexturecache.h
+++ b/linden/indra/newview/lltexturecache.h
@@ -158,6 +158,7 @@ private:
158 S32 getHeaderCacheEntry(const LLUUID& id, S32& imagesize); 158 S32 getHeaderCacheEntry(const LLUUID& id, S32& imagesize);
159 S32 setHeaderCacheEntry(const LLUUID& id, S32 imagesize); 159 S32 setHeaderCacheEntry(const LLUUID& id, S32 imagesize);
160 bool removeHeaderCacheEntry(const LLUUID& id); 160 bool removeHeaderCacheEntry(const LLUUID& id);
161 void removeFromCacheLocked(const LLUUID& id);
161 162
162private: 163private:
163 // Internal 164 // Internal