From 3bde58d97072f40305ba8e39622b1a9e15a0cb48 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Fri, 5 Aug 2011 00:05:08 +0200 Subject: [PATCH] Wrap sGlobalRawMemory in AIThreadSafe. This is accessed by different threads. Other globals like it might also be accessed by different threads, this has to be investigated. --- indra/llimage/llimage.cpp | 14 ++++++++------ indra/llimage/llimage.h | 3 ++- indra/newview/lltextureview.cpp | 6 +++++- indra/newview/llviewerstats.cpp | 6 +++++- indra/newview/llviewertexturelist.cpp | 6 +++++- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp index 00ed4e469..73b4b7b90 100644 --- a/indra/llimage/llimage.cpp +++ b/indra/llimage/llimage.cpp @@ -245,7 +245,7 @@ U8* LLImageBase::allocateDataSize(S32 width, S32 height, S32 ncomponents, S32 si // LLImageRaw //--------------------------------------------------------------------------- -S32 LLImageRaw::sGlobalRawMemory = 0; +AITHREADSAFESIMPLE(S32, LLImageRaw::sGlobalRawMemory, ); S32 LLImageRaw::sRawImageCount = 0; S32 LLImageRaw::sRawImageCachedCount = 0; @@ -295,23 +295,25 @@ LLImageRaw::~LLImageRaw() U8* LLImageRaw::allocateData(S32 size) { U8* res = LLImageBase::allocateData(size); - sGlobalRawMemory += getDataSize(); + *AIAccess(sGlobalRawMemory) += getDataSize(); return res; } // virtual U8* LLImageRaw::reallocateData(S32 size) { - sGlobalRawMemory -= getDataSize(); + S32 old_data_size = getDataSize(); U8* res = LLImageBase::reallocateData(size); - sGlobalRawMemory += getDataSize(); + *AIAccess(sGlobalRawMemory) += getDataSize() - old_data_size; return res; } // virtual void LLImageRaw::deleteData() { - sGlobalRawMemory -= getDataSize(); + { + *AIAccess(sGlobalRawMemory) -= getDataSize(); + } LLImageBase::deleteData(); } @@ -327,7 +329,7 @@ void LLImageRaw::setDataAndSize(U8 *data, S32 width, S32 height, S8 components) LLImageBase::setSize(width, height, components) ; LLImageBase::setDataAndSize(data, width * height * components) ; - sGlobalRawMemory += getDataSize(); + *AIAccess(sGlobalRawMemory) += getDataSize(); } BOOL LLImageRaw::resize(U16 width, U16 height, S8 components) diff --git a/indra/llimage/llimage.h b/indra/llimage/llimage.h index 9f0cfa87d..99b07be84 100644 --- a/indra/llimage/llimage.h +++ b/indra/llimage/llimage.h @@ -37,6 +37,7 @@ #include "llstring.h" #include "llmemory.h" #include "llthread.h" +#include "aithreadsafe.h" const S32 MIN_IMAGE_MIP = 2; // 4x4, only used for expand/contract power of 2 const S32 MAX_IMAGE_MIP = 11; // 2048x2048 @@ -241,7 +242,7 @@ protected: void setDataAndSize(U8 *data, S32 width, S32 height, S8 components) ; public: - static S32 sGlobalRawMemory; + static AIThreadSafeSimple sGlobalRawMemory; static S32 sRawImageCount; static S32 sRawImageCachedCount; diff --git a/indra/newview/lltextureview.cpp b/indra/newview/lltextureview.cpp index 2ce0c5ff4..736a6dafa 100644 --- a/indra/newview/lltextureview.cpp +++ b/indra/newview/lltextureview.cpp @@ -421,12 +421,16 @@ void LLGLTexMemBar::draw() std::string text; + S32 global_raw_memory; + { + global_raw_memory = *AIAccess(LLImageRaw::sGlobalRawMemory); + } text = llformat("GL Tot: %d/%d MB Bound: %d/%d MB Raw Tot: %d MB Bias: %.2f Cache: %.1f/%.1f MB Net Tot Tex: %.1f MB Tot Obj: %.1f MB", total_mem, max_total_mem, bound_mem, max_bound_mem, - LLImageRaw::sGlobalRawMemory >> 20, discard_bias, + global_raw_memory >> 20, discard_bias, cache_usage, cache_max_usage, total_texture_downloaded, total_object_downloaded); //, cache_entries, cache_max_entries diff --git a/indra/newview/llviewerstats.cpp b/indra/newview/llviewerstats.cpp index 3f24ba674..2c9468743 100644 --- a/indra/newview/llviewerstats.cpp +++ b/indra/newview/llviewerstats.cpp @@ -362,12 +362,16 @@ void reset_statistics() void output_statistics(void*) { + S32 global_raw_memory; + { + global_raw_memory = *AIAccess(LLImageRaw::sGlobalRawMemory); + } llinfos << "Number of orphans: " << gObjectList.getOrphanCount() << llendl; llinfos << "Number of dead objects: " << gObjectList.mNumDeadObjects << llendl; llinfos << "Num images: " << gTextureList.getNumImages() << llendl; llinfos << "Texture usage: " << LLImageGL::sGlobalTextureMemoryInBytes << llendl; llinfos << "Texture working set: " << LLImageGL::sBoundTextureMemoryInBytes << llendl; - llinfos << "Raw usage: " << LLImageRaw::sGlobalRawMemory << llendl; + llinfos << "Raw usage: " << global_raw_memory << llendl; llinfos << "Formatted usage: " << LLImageFormatted::sGlobalFormattedMemory << llendl; llinfos << "Zombie Viewer Objects: " << LLViewerObject::getNumZombieObjects() << llendl; llinfos << "Number of lights: " << gPipeline.getLightCount() << llendl; diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp index c5b973af5..997823268 100644 --- a/indra/newview/llviewertexturelist.cpp +++ b/indra/newview/llviewertexturelist.cpp @@ -608,11 +608,15 @@ void LLViewerTextureList::updateImages(F32 max_time) { LLAppViewer::getTextureFetch()->setTextureBandwidth(LLViewerStats::getInstance()->mTextureKBitStat.getMeanPerSec()); + S32 global_raw_memory; + { + global_raw_memory = *AIAccess(LLImageRaw::sGlobalRawMemory); + } sNumImagesStat.addValue(sNumImages); sNumRawImagesStat.addValue(LLImageRaw::sRawImageCount); sGLTexMemStat.addValue((F32)BYTES_TO_MEGA_BYTES(LLImageGL::sGlobalTextureMemoryInBytes)); sGLBoundMemStat.addValue((F32)BYTES_TO_MEGA_BYTES(LLImageGL::sBoundTextureMemoryInBytes)); - sRawMemStat.addValue((F32)BYTES_TO_MEGA_BYTES(LLImageRaw::sGlobalRawMemory)); + sRawMemStat.addValue((F32)BYTES_TO_MEGA_BYTES(global_raw_memory)); sFormattedMemStat.addValue((F32)BYTES_TO_MEGA_BYTES(LLImageFormatted::sGlobalFormattedMemory)); updateImagesDecodePriorities();