From d96e672c7fa0cb59ef0c30163326bb40220e745a Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Mon, 8 Feb 2010 17:01:00 -0600 Subject: Ported many APR changes from Snowglobe. --- ChangeLog.txt | 26 ++ linden/indra/llaudio/vorbisencode.cpp | 6 +- linden/indra/llcharacter/llbvhloader.cpp | 2 +- linden/indra/llcharacter/llkeyframemotionparam.cpp | 2 +- linden/indra/llcharacter/llstatemachine.cpp | 2 +- linden/indra/llcommon/llapr.cpp | 284 +++++++++++---------- linden/indra/llcommon/llapr.h | 47 ++-- linden/indra/llcommon/llthread.cpp | 11 +- linden/indra/llcommon/llthread.h | 6 - linden/indra/llcommon/llworkerthread.cpp | 5 - linden/indra/llimage/llimage.cpp | 4 +- linden/indra/llimage/llimagej2c.cpp | 2 +- linden/indra/llmessage/llcurl.cpp | 2 +- linden/indra/llvfs/lllfsthread.cpp | 8 +- linden/indra/llvfs/llvfs.cpp | 2 +- linden/indra/newview/llappviewer.cpp | 18 +- linden/indra/newview/llfloateranimpreview.cpp | 2 +- linden/indra/newview/lltexturecache.cpp | 73 +++--- linden/indra/newview/llviewermenufile.cpp | 2 +- linden/indra/newview/llvoavatar.cpp | 2 +- linden/indra/newview/primbackup.cpp | 2 +- 21 files changed, 257 insertions(+), 251 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 66e848c..46f37cb 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,29 @@ +2010-02-08 Jacek Antonelli + + * Ported many APR changes from Snowglobe. + + modified: linden/indra/llaudio/vorbisencode.cpp + modified: linden/indra/llcharacter/llbvhloader.cpp + modified: linden/indra/llcharacter/llkeyframemotionparam.cpp + modified: linden/indra/llcharacter/llstatemachine.cpp + modified: linden/indra/llcommon/llapr.cpp + modified: linden/indra/llcommon/llapr.h + modified: linden/indra/llcommon/llthread.cpp + modified: linden/indra/llcommon/llthread.h + modified: linden/indra/llcommon/llworkerthread.cpp + modified: linden/indra/llimage/llimage.cpp + modified: linden/indra/llimage/llimagej2c.cpp + modified: linden/indra/llmessage/llcurl.cpp + modified: linden/indra/llvfs/lllfsthread.cpp + modified: linden/indra/llvfs/llvfs.cpp + modified: linden/indra/newview/llappviewer.cpp + modified: linden/indra/newview/llfloateranimpreview.cpp + modified: linden/indra/newview/lltexturecache.cpp + modified: linden/indra/newview/llviewermenufile.cpp + modified: linden/indra/newview/llvoavatar.cpp + modified: linden/indra/newview/primbackup.cpp + + 2010-02-07 Jacek Antonelli * Fixed login screen only allowing 16 chars per name. diff --git a/linden/indra/llaudio/vorbisencode.cpp b/linden/indra/llaudio/vorbisencode.cpp index 7df1416..57e7724 100644 --- a/linden/indra/llaudio/vorbisencode.cpp +++ b/linden/indra/llaudio/vorbisencode.cpp @@ -88,7 +88,7 @@ S32 check_for_invalid_wav_formats(const std::string& in_fname, std::string& erro //******************************** LLAPRFile infile ; - infile.open(in_fname,LL_APR_RB); + infile.open(in_fname,LL_APR_RB, LLAPRFile::global); //******************************** if (!infile.getFileHandle()) { @@ -232,7 +232,7 @@ S32 encode_vorbis_file(const std::string& in_fname, const std::string& out_fname S32 data_left = 0; LLAPRFile infile ; - infile.open(in_fname,LL_APR_RB); + infile.open(in_fname,LL_APR_RB, LLAPRFile::global); if (!infile.getFileHandle()) { llwarns << "Couldn't open temporary ogg file for writing: " << in_fname @@ -241,7 +241,7 @@ S32 encode_vorbis_file(const std::string& in_fname, const std::string& out_fname } LLAPRFile outfile ; - outfile.open(out_fname,LL_APR_WPB); + outfile.open(out_fname,LL_APR_WPB, LLAPRFile::global); if (!outfile.getFileHandle()) { llwarns << "Couldn't open upload sound file for reading: " << in_fname diff --git a/linden/indra/llcharacter/llbvhloader.cpp b/linden/indra/llcharacter/llbvhloader.cpp index e1f8ce5..49b6d82 100644 --- a/linden/indra/llcharacter/llbvhloader.cpp +++ b/linden/indra/llcharacter/llbvhloader.cpp @@ -179,7 +179,7 @@ LLBVHLoader::Status LLBVHLoader::loadTranslationTable(const char *fileName) std::string path = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,fileName); LLAPRFile infile ; - infile.open(path, LL_APR_R); + infile.open(path, LL_APR_R, LLAPRFile::global); apr_file_t *fp = infile.getFileHandle(); if (!fp) return ST_NO_XLT_FILE; diff --git a/linden/indra/llcharacter/llkeyframemotionparam.cpp b/linden/indra/llcharacter/llkeyframemotionparam.cpp index a9c1f6f..3692bf6 100644 --- a/linden/indra/llcharacter/llkeyframemotionparam.cpp +++ b/linden/indra/llcharacter/llkeyframemotionparam.cpp @@ -355,7 +355,7 @@ BOOL LLKeyframeMotionParam::loadMotions() //------------------------------------------------------------------------- S32 fileSize = 0; LLAPRFile infile ; - infile.open(path, LL_APR_R, NULL, &fileSize); + infile.open(path, LL_APR_R, LLAPRFile::global, &fileSize); apr_file_t* fp = infile.getFileHandle() ; if (!fp || fileSize == 0) { diff --git a/linden/indra/llcharacter/llstatemachine.cpp b/linden/indra/llcharacter/llstatemachine.cpp index 73c6951..71e2eaa 100644 --- a/linden/indra/llcharacter/llstatemachine.cpp +++ b/linden/indra/llcharacter/llstatemachine.cpp @@ -210,7 +210,7 @@ LLFSMState* LLStateDiagram::getState(U32 state_id) BOOL LLStateDiagram::saveDotFile(const std::string& filename) { LLAPRFile outfile ; - outfile.open(filename, LL_APR_W); + outfile.open(filename, LL_APR_W, LLAPRFile::global); apr_file_t* dot_file = outfile.getFileHandle() ; if (!dot_file) diff --git a/linden/indra/llcommon/llapr.cpp b/linden/indra/llcommon/llapr.cpp index 669afc5..7e3a26c 100644 --- a/linden/indra/llcommon/llapr.cpp +++ b/linden/indra/llcommon/llapr.cpp @@ -36,7 +36,6 @@ #include "llapr.h" apr_pool_t *gAPRPoolp = NULL; // Global APR memory pool -LLVolatileAPRPool *LLAPRFile::sAPRFilePoolp = NULL ; //global volatile APR memory pool. apr_thread_mutex_t *gLogMutexp = NULL; apr_thread_mutex_t *gCallStacksLogMutexp = NULL; @@ -53,11 +52,9 @@ void ll_init_apr() // Initialize the logging mutex apr_thread_mutex_create(&gLogMutexp, APR_THREAD_MUTEX_UNNESTED, gAPRPoolp); apr_thread_mutex_create(&gCallStacksLogMutexp, APR_THREAD_MUTEX_UNNESTED, gAPRPoolp); - } - if(!LLAPRFile::sAPRFilePoolp) - { - LLAPRFile::sAPRFilePoolp = new LLVolatileAPRPool() ; + // Initialize thread-local APR pool support. + LLVolatileAPRPool::initLocalAPRFilePool(); } } @@ -87,11 +84,6 @@ void ll_cleanup_apr() apr_pool_destroy(gAPRPoolp); gAPRPoolp = NULL; } - if (LLAPRFile::sAPRFilePoolp) - { - delete LLAPRFile::sAPRFilePoolp ; - LLAPRFile::sAPRFilePoolp = NULL ; - } apr_terminate(); } @@ -207,6 +199,56 @@ BOOL LLVolatileAPRPool::isFull() { return mNumTotalRef > FULL_VOLATILE_APR_POOL ; } + +#ifdef SHOW_ASSERT +// This allows the use of llassert(is_main_thread()) to assure the current thread is the main thread. +static void* gIsMainThread; +bool is_main_thread() { return gIsMainThread == LLVolatileAPRPool::getLocalAPRFilePool(); } +#endif + +// The thread private handle to access the LocalAPRFilePool. +apr_threadkey_t* LLVolatileAPRPool::sLocalAPRFilePoolKey; + +// This should be called exactly once, before the first call to createLocalAPRFilePool. +// static +void LLVolatileAPRPool::initLocalAPRFilePool() +{ + apr_status_t status = apr_threadkey_private_create(&sLocalAPRFilePoolKey, &destroyLocalAPRFilePool, gAPRPoolp); + ll_apr_assert_status(status); // Or out of memory, or system-imposed limit on the + // total number of keys per process {PTHREAD_KEYS_MAX} + // has been exceeded. + // Create the thread-local pool for the main thread (this function is called by the main thread). + createLocalAPRFilePool(); +#ifdef SHOW_ASSERT + gIsMainThread = getLocalAPRFilePool(); +#endif +} + +// This should be called once for every thread, before it uses getLocalAPRFilePool. +// static +void LLVolatileAPRPool::createLocalAPRFilePool() +{ + void* thread_local_data = new LLVolatileAPRPool; + apr_status_t status = apr_threadkey_private_set(thread_local_data, sLocalAPRFilePoolKey); + llassert_always(status == APR_SUCCESS); +} + +// This is called once for every thread when the thread is destructed. +// static +void LLVolatileAPRPool::destroyLocalAPRFilePool(void* thread_local_data) +{ + delete reinterpret_cast(thread_local_data); +} + +// static +LLVolatileAPRPool* LLVolatileAPRPool::getLocalAPRFilePool() +{ + void* thread_local_data; + apr_status_t status = apr_threadkey_private_get(&thread_local_data, sLocalAPRFilePoolKey); + llassert_always(status == APR_SUCCESS); + return reinterpret_cast(thread_local_data); +} + //--------------------------------------------------------------------- // // LLScopedLock @@ -251,10 +293,9 @@ void LLScopedLock::unlock() bool ll_apr_warn_status(apr_status_t status) { if(APR_SUCCESS == status) return false; -#ifndef LL_WINDOWS char buf[MAX_STRING]; /* Flawfinder: ignore */ - LL_WARNS_ONCE("APR") << "APR: " << apr_strerror(status, buf, MAX_STRING) << LL_ENDL; -#endif + apr_strerror(status, buf, MAX_STRING); + LL_WARNS("APR") << "APR: " << buf << LL_ENDL; return true; } @@ -268,10 +309,18 @@ void ll_apr_assert_status(apr_status_t status) // LLAPRFile functions // LLAPRFile::LLAPRFile() + : mFile(NULL), + mCurrentFilePoolp(NULL) { - mFile = NULL ; - mCurrentFilePoolp = NULL ; } + +LLAPRFile::LLAPRFile(const std::string& filename, apr_int32_t flags, access_t access_type) + : mFile(NULL), + mCurrentFilePoolp(NULL) +{ + open(filename, flags, access_type); +} + LLAPRFile::~LLAPRFile() { close() ; @@ -295,32 +344,27 @@ apr_status_t LLAPRFile::close() return ret ; } -apr_status_t LLAPRFile::open(LLVolatileAPRPool* pool, const std::string& filename, apr_int32_t flags, S32* sizep) +apr_status_t LLAPRFile::open(std::string const& filename, apr_int32_t flags, access_t access_type, S32* sizep) { - apr_status_t s ; - s = open(filename, flags, pool ? pool->getVolatileAPRPool() : NULL, sizep) ; - - if(!mCurrentFilePoolp) - { - mCurrentFilePoolp = pool ; + llassert_always(!mFile); + llassert_always(!mCurrentFilePoolp); - if(!mFile) - { - close() ; - } + // Access the pool and increment it's reference count. + // The reference count of LLVolatileAPRPool objects will be decremented + // again in LLAPRFile::close by calling mCurrentFilePoolp->clearVolatileAPRPool(). + apr_pool_t* pool; + if (access_type == local) + { + // Use a "volatile" thread-local pool. + mCurrentFilePoolp = LLVolatileAPRPool::getLocalAPRFilePool(); + pool = mCurrentFilePoolp->getVolatileAPRPool(); } - - return s ; -} -apr_status_t LLAPRFile::open(const std::string& filename, apr_int32_t flags, apr_pool_t* pool, S32* sizep) -{ - apr_status_t s; - - //check if already open some file - llassert_always(!mFile) ; - llassert_always(!mCurrentFilePoolp) ; - - s = apr_file_open(&mFile, filename.c_str(), flags, APR_OS_DEFAULT, getAPRFilePool(pool)); + else + { + llassert(is_main_thread()); + pool = gAPRPoolp; + } + apr_status_t s = apr_file_open(&mFile, filename.c_str(), flags, APR_OS_DEFAULT, pool); if (s != APR_SUCCESS || !mFile) { mFile = NULL ; @@ -349,17 +393,6 @@ apr_status_t LLAPRFile::open(const std::string& filename, apr_int32_t flags, apr return s; } -apr_pool_t* LLAPRFile::getAPRFilePool(apr_pool_t* pool) -{ - if(!pool) - { - mCurrentFilePoolp = sAPRFilePoolp ; - return mCurrentFilePoolp->getVolatileAPRPool() ; - } - - return pool ; -} - // File I/O S32 LLAPRFile::read(void *buf, S32 nbytes) { @@ -369,6 +402,7 @@ S32 LLAPRFile::read(void *buf, S32 nbytes) apr_status_t s = apr_file_read(mFile, buf, &sz); if (s != APR_SUCCESS) { + ll_apr_warn_status(s); return 0; } else @@ -386,6 +420,7 @@ S32 LLAPRFile::write(const void *buf, S32 nbytes) apr_status_t s = apr_file_write(mFile, buf, &sz); if (s != APR_SUCCESS) { + ll_apr_warn_status(s); return 0; } else @@ -405,42 +440,16 @@ S32 LLAPRFile::seek(apr_seek_where_t where, S32 offset) //static components of LLAPRFile // -//static -apr_status_t LLAPRFile::close(apr_file_t* file_handle, LLVolatileAPRPool* pool) -{ - apr_status_t ret = APR_SUCCESS ; - if(file_handle) - { - ret = apr_file_close(file_handle); - file_handle = NULL ; - } - - if(pool) - { - pool->clearVolatileAPRPool() ; - } - - return ret ; -} - -//static -apr_file_t* LLAPRFile::open(const std::string& filename, LLVolatileAPRPool* pool, apr_int32_t flags) -{ - apr_status_t s; - apr_file_t* file_handle ; - - pool = pool ? pool : LLAPRFile::sAPRFilePoolp ; - - s = apr_file_open(&file_handle, filename.c_str(), flags, APR_OS_DEFAULT, pool->getVolatileAPRPool()); - if (s != APR_SUCCESS || !file_handle) - { - file_handle = NULL ; - close(file_handle, pool) ; - return NULL; - } - - return file_handle ; -} +// Used in the static functions below. +class LLScopedVolatileAPRFilePool { +private: + LLVolatileAPRPool* mPool; + apr_pool_t* apr_pool; +public: + LLScopedVolatileAPRFilePool() : mPool(LLVolatileAPRPool::getLocalAPRFilePool()), apr_pool(mPool->getVolatileAPRPool()) { } + ~LLScopedVolatileAPRFilePool() { mPool->clearVolatileAPRPool(); } + operator apr_pool_t*() const { return apr_pool; } +}; //static S32 LLAPRFile::seek(apr_file_t* file_handle, apr_seek_where_t where, S32 offset) @@ -464,6 +473,7 @@ S32 LLAPRFile::seek(apr_file_t* file_handle, apr_seek_where_t where, S32 offset) } if (s != APR_SUCCESS) { + ll_apr_warn_status(s); return -1; } else @@ -474,13 +484,15 @@ S32 LLAPRFile::seek(apr_file_t* file_handle, apr_seek_where_t where, S32 offset) } //static -S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool) +S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes) { - //***************************************** - apr_file_t* file_handle = open(filename, pool, APR_READ|APR_BINARY); - //***************************************** - if (!file_handle) + apr_file_t* file_handle; + LLScopedVolatileAPRFilePool pool; + apr_status_t s = apr_file_open(&file_handle, filename.c_str(), APR_READ|APR_BINARY, APR_OS_DEFAULT, pool); + if (s != APR_SUCCESS || !file_handle) { + ll_apr_warn_status(s); + LL_WARNS("APR") << " while attempting to open file \"" << filename << '"' << LL_ENDL; return 0; } @@ -501,6 +513,8 @@ S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nb apr_status_t s = apr_file_read(file_handle, buf, &bytes_read); if (s != APR_SUCCESS) { + LL_WARNS("APR") << " Attempting to read filename: " << filename << LL_ENDL; + ll_apr_warn_status(s); bytes_read = 0; } else @@ -509,14 +523,13 @@ S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nb } } - //***************************************** - close(file_handle, pool) ; - //***************************************** + apr_file_close(file_handle); + return (S32)bytes_read; } //static -S32 LLAPRFile::writeEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool) +S32 LLAPRFile::writeEx(const std::string& filename, void *buf, S32 offset, S32 nbytes) { apr_int32_t flags = APR_CREATE|APR_WRITE|APR_BINARY; if (offset < 0) @@ -525,11 +538,13 @@ S32 LLAPRFile::writeEx(const std::string& filename, void *buf, S32 offset, S32 n offset = 0; } - //***************************************** - apr_file_t* file_handle = open(filename, pool, flags); - //***************************************** - if (!file_handle) + apr_file_t* file_handle; + LLScopedVolatileAPRFilePool pool; + apr_status_t s = apr_file_open(&file_handle, filename.c_str(), flags, APR_OS_DEFAULT, pool); + if (s != APR_SUCCESS || !file_handle) { + ll_apr_warn_status(s); + LL_WARNS("APR") << " while attempting to open file \"" << filename << '"' << LL_ENDL; return 0; } @@ -549,6 +564,8 @@ S32 LLAPRFile::writeEx(const std::string& filename, void *buf, S32 offset, S32 n apr_status_t s = apr_file_write(file_handle, buf, &bytes_written); if (s != APR_SUCCESS) { + LL_WARNS("APR") << " Attempting to write filename: " << filename << LL_ENDL; + ll_apr_warn_status(s); bytes_written = 0; } else @@ -557,93 +574,84 @@ S32 LLAPRFile::writeEx(const std::string& filename, void *buf, S32 offset, S32 n } } - //***************************************** - LLAPRFile::close(file_handle, pool); - //***************************************** + apr_file_close(file_handle); return (S32)bytes_written; } //static -bool LLAPRFile::remove(const std::string& filename, LLVolatileAPRPool* pool) +bool LLAPRFile::remove(const std::string& filename) { apr_status_t s; - pool = pool ? pool : LLAPRFile::sAPRFilePoolp ; - s = apr_file_remove(filename.c_str(), pool->getVolatileAPRPool()); - pool->clearVolatileAPRPool() ; + LLScopedVolatileAPRFilePool pool; + s = apr_file_remove(filename.c_str(), pool); if (s != APR_SUCCESS) { - LL_DEBUGS("APR") << "LLAPRFile::remove failed on file: " << filename << LL_ENDL; ll_apr_warn_status(s); + LL_WARNS("APR") << " Attempting to remove filename: " << filename << LL_ENDL; return false; } return true; } //static -bool LLAPRFile::rename(const std::string& filename, const std::string& newname, LLVolatileAPRPool* pool) +bool LLAPRFile::rename(const std::string& filename, const std::string& newname) { apr_status_t s; - pool = pool ? pool : LLAPRFile::sAPRFilePoolp ; - s = apr_file_rename(filename.c_str(), newname.c_str(), pool->getVolatileAPRPool()); - pool->clearVolatileAPRPool() ; + LLScopedVolatileAPRFilePool pool; + s = apr_file_rename(filename.c_str(), newname.c_str(), pool); if (s != APR_SUCCESS) { - LL_DEBUGS("APR") << "LLAPRFile::rename failed on file: " << filename << LL_ENDL; ll_apr_warn_status(s); + LL_WARNS("APR") << " Attempting to rename filename: " << filename << LL_ENDL; return false; } return true; } //static -bool LLAPRFile::isExist(const std::string& filename, LLVolatileAPRPool* pool, apr_int32_t flags) +bool LLAPRFile::isExist(const std::string& filename, apr_int32_t flags) { - apr_file_t* apr_file; + apr_file_t* file_handle; apr_status_t s; - pool = pool ? pool : LLAPRFile::sAPRFilePoolp ; - s = apr_file_open(&apr_file, filename.c_str(), flags, APR_OS_DEFAULT, pool->getVolatileAPRPool()); + LLScopedVolatileAPRFilePool pool; + s = apr_file_open(&file_handle, filename.c_str(), flags, APR_OS_DEFAULT, pool); - if (s != APR_SUCCESS || !apr_file) + if (s != APR_SUCCESS || !file_handle) { - pool->clearVolatileAPRPool() ; return false; } else { - apr_file_close(apr_file) ; - pool->clearVolatileAPRPool() ; + apr_file_close(file_handle); return true; } } //static -S32 LLAPRFile::size(const std::string& filename, LLVolatileAPRPool* pool) +S32 LLAPRFile::size(const std::string& filename) { - apr_file_t* apr_file; + apr_file_t* file_handle; apr_finfo_t info; apr_status_t s; - pool = pool ? pool : LLAPRFile::sAPRFilePoolp ; - s = apr_file_open(&apr_file, filename.c_str(), APR_READ, APR_OS_DEFAULT, pool->getVolatileAPRPool()); + LLScopedVolatileAPRFilePool pool; + s = apr_file_open(&file_handle, filename.c_str(), APR_READ, APR_OS_DEFAULT, pool); - if (s != APR_SUCCESS || !apr_file) + if (s != APR_SUCCESS || !file_handle) { - pool->clearVolatileAPRPool() ; - return 0; } else { - apr_status_t s = apr_file_info_get(&info, APR_FINFO_SIZE, apr_file); + apr_status_t s = apr_file_info_get(&info, APR_FINFO_SIZE, file_handle); - apr_file_close(apr_file) ; - pool->clearVolatileAPRPool() ; + apr_file_close(file_handle) ; if (s == APR_SUCCESS) { @@ -657,36 +665,34 @@ S32 LLAPRFile::size(const std::string& filename, LLVolatileAPRPool* pool) } //static -bool LLAPRFile::makeDir(const std::string& dirname, LLVolatileAPRPool* pool) +bool LLAPRFile::makeDir(const std::string& dirname) { apr_status_t s; - pool = pool ? pool : LLAPRFile::sAPRFilePoolp ; - s = apr_dir_make(dirname.c_str(), APR_FPROT_OS_DEFAULT, pool->getVolatileAPRPool()); - pool->clearVolatileAPRPool() ; + LLScopedVolatileAPRFilePool pool; + s = apr_dir_make(dirname.c_str(), APR_FPROT_OS_DEFAULT, pool); if (s != APR_SUCCESS) { - LL_DEBUGS("APR") << "LLAPRFile::makeDir failed on file: " << dirname << LL_ENDL; ll_apr_warn_status(s); + LL_WARNS("APR") << " while attempting to make directory: " << dirname << LL_ENDL; return false; } return true; } //static -bool LLAPRFile::removeDir(const std::string& dirname, LLVolatileAPRPool* pool) +bool LLAPRFile::removeDir(const std::string& dirname) { apr_status_t s; - pool = pool ? pool : LLAPRFile::sAPRFilePoolp ; - s = apr_file_remove(dirname.c_str(), pool->getVolatileAPRPool()); - pool->clearVolatileAPRPool() ; + LLScopedVolatileAPRFilePool pool; + s = apr_file_remove(dirname.c_str(), pool); if (s != APR_SUCCESS) { - LL_DEBUGS("APR") << "LLAPRFile::removeDir failed on file: " << dirname << LL_ENDL; ll_apr_warn_status(s); + LL_WARNS("APR") << " Attempting to remove directory: " << dirname << LL_ENDL; return false; } return true; diff --git a/linden/indra/llcommon/llapr.h b/linden/indra/llcommon/llapr.h index 63130a8..7f770b0 100644 --- a/linden/indra/llcommon/llapr.h +++ b/linden/indra/llcommon/llapr.h @@ -92,7 +92,7 @@ protected: //which clears memory automatically. //so it can not hold static data or data after memory is cleared // -class LLVolatileAPRPool : public LLAPRPool +class LLVolatileAPRPool : protected LLAPRPool { public: LLVolatileAPRPool(apr_pool_t *parent = NULL, apr_size_t size = 0, BOOL releasePoolFlag = TRUE); @@ -104,9 +104,17 @@ public: BOOL isFull() ; BOOL isEmpty() {return !mNumActiveRef ;} + + static void initLocalAPRFilePool(); + static void createLocalAPRFilePool(); + static void destroyLocalAPRFilePool(void* thread_local_data); + static LLVolatileAPRPool* getLocalAPRFilePool(); + private: S32 mNumActiveRef ; //number of active pointers pointing to the apr_pool. S32 mNumTotalRef ; //number of total pointers pointing to the apr_pool since last creating. + + static apr_threadkey_t* sLocalAPRFilePoolKey; } ; /** @@ -192,18 +200,25 @@ typedef LLAtomic32 LLAtomicS32; // 1, a temperary pool passed to an APRFile function, which is used within this function and only once. // 2, a global pool. // -class LLAPRFile + +class LLAPRFile : boost::noncopyable { + // make this non copyable since a copy closes the file private: apr_file_t* mFile ; LLVolatileAPRPool *mCurrentFilePoolp ; //currently in use apr_pool, could be one of them: sAPRFilePoolp, or a temp pool. public: + enum access_t { + global, // Use a global pool for long-lived file accesses. This should really only happen from the main thread. + local // Use a thread-local volatile pool for short file accesses. + }; + LLAPRFile() ; + LLAPRFile(const std::string& filename, apr_int32_t flags, access_t access_type); ~LLAPRFile() ; - apr_status_t open(LLVolatileAPRPool* pool, const std::string& filename, apr_int32_t flags, S32* sizep = NULL); - apr_status_t open(const std::string& filename, apr_int32_t flags, apr_pool_t* pool = NULL, S32* sizep = NULL); + apr_status_t open(const std::string& filename, apr_int32_t flags, access_t access_type, S32* sizep = NULL); apr_status_t close() ; // Returns actual offset, -1 if seek fails @@ -216,32 +231,24 @@ public: apr_file_t* getFileHandle() {return mFile;} -private: - apr_pool_t* getAPRFilePool(apr_pool_t* pool) ; - // //******************************************************************************************************************************* //static components // -public: - static LLVolatileAPRPool *sAPRFilePoolp ; //a global apr_pool for APRFile, which is used only when local pool does not exist. - private: - static apr_file_t* open(const std::string& filename, LLVolatileAPRPool* pool, apr_int32_t flags); - static apr_status_t close(apr_file_t* file, LLVolatileAPRPool* pool) ; static S32 seek(apr_file_t* file, apr_seek_where_t where, S32 offset); public: // returns false if failure: - static bool remove(const std::string& filename, LLVolatileAPRPool* pool = NULL); - static bool rename(const std::string& filename, const std::string& newname, LLVolatileAPRPool* pool = NULL); - static bool isExist(const std::string& filename, LLVolatileAPRPool* pool = NULL, apr_int32_t flags = APR_READ); - static S32 size(const std::string& filename, LLVolatileAPRPool* pool = NULL); - static bool makeDir(const std::string& dirname, LLVolatileAPRPool* pool = NULL); - static bool removeDir(const std::string& dirname, LLVolatileAPRPool* pool = NULL); + static bool remove(const std::string& filename); + static bool rename(const std::string& filename, const std::string& newname); + static bool isExist(const std::string& filename, apr_int32_t flags = APR_READ); + static S32 size(const std::string& filename); + static bool makeDir(const std::string& dirname); + static bool removeDir(const std::string& dirname); // Returns bytes read/written, 0 if read/write fails: - static S32 readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool = NULL); - static S32 writeEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool = NULL); + static S32 readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes); + static S32 writeEx(const std::string& filename, void *buf, S32 offset, S32 nbytes); //******************************************************************************************************************************* }; diff --git a/linden/indra/llcommon/llthread.cpp b/linden/indra/llcommon/llthread.cpp index 37b03a4..b39ffb6 100644 --- a/linden/indra/llcommon/llthread.cpp +++ b/linden/indra/llcommon/llthread.cpp @@ -72,6 +72,9 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap // Set thread state to running threadp->mStatus = RUNNING; + // Create a thread local APRFile pool. + LLVolatileAPRPool::createLocalAPRFilePool(); + // Run the user supplied function threadp->run(); @@ -102,20 +105,12 @@ LLThread::LLThread(const std::string& name, apr_pool_t *poolp) : apr_pool_create(&mAPRPoolp, NULL); // Create a subpool for this thread } mRunCondition = new LLCondition(mAPRPoolp); - - mLocalAPRFilePoolp = NULL ; } LLThread::~LLThread() { shutdown(); - - if(mLocalAPRFilePoolp) - { - delete mLocalAPRFilePoolp ; - mLocalAPRFilePoolp = NULL ; - } } void LLThread::shutdown() diff --git a/linden/indra/llcommon/llthread.h b/linden/indra/llcommon/llthread.h index 457f45b..721b6e7 100644 --- a/linden/indra/llcommon/llthread.h +++ b/linden/indra/llcommon/llthread.h @@ -83,7 +83,6 @@ public: void start(void); apr_pool_t *getAPRPool() { return mAPRPoolp; } - LLVolatileAPRPool* getLocalAPRFilePool() { return mLocalAPRFilePoolp ; } private: bool mPaused; @@ -100,11 +99,6 @@ protected: bool mIsLocalPool; EThreadStatus mStatus; - //a local apr_pool for APRFile operations in this thread. If it exists, LLAPRFile::sAPRFilePoolp should not be used. - //Note: this pool is used by APRFile ONLY, do NOT use it for any other purposes. - // otherwise it will cause severe memory leaking!!! --bao - LLVolatileAPRPool *mLocalAPRFilePoolp ; - void setQuitting(); // virtual function overridden by subclass -- this will be called when the thread runs diff --git a/linden/indra/llcommon/llworkerthread.cpp b/linden/indra/llcommon/llworkerthread.cpp index 5dda600..68d32db 100644 --- a/linden/indra/llcommon/llworkerthread.cpp +++ b/linden/indra/llcommon/llworkerthread.cpp @@ -44,11 +44,6 @@ LLWorkerThread::LLWorkerThread(const std::string& name, bool threaded) : LLQueuedThread(name, threaded) { mDeleteMutex = new LLMutex(NULL); - - if(!mLocalAPRFilePoolp) - { - mLocalAPRFilePoolp = new LLVolatileAPRPool() ; - } } LLWorkerThread::~LLWorkerThread() diff --git a/linden/indra/llimage/llimage.cpp b/linden/indra/llimage/llimage.cpp index 88edc99..4b0076e 100644 --- a/linden/indra/llimage/llimage.cpp +++ b/linden/indra/llimage/llimage.cpp @@ -1514,7 +1514,7 @@ BOOL LLImageFormatted::load(const std::string &filename) S32 file_size = 0; LLAPRFile infile ; - infile.open(filename, LL_APR_RB, NULL, &file_size); + infile.open(filename, LL_APR_RB, LLAPRFile::global, &file_size); apr_file_t* apr_file = infile.getFileHandle(); if (!apr_file) { @@ -1550,7 +1550,7 @@ BOOL LLImageFormatted::save(const std::string &filename) resetLastError(); LLAPRFile outfile ; - outfile.open(filename, LL_APR_WB); + outfile.open(filename, LL_APR_WB, LLAPRFile::global); if (!outfile.getFileHandle()) { setLastError("Unable to open file for writing", filename); diff --git a/linden/indra/llimage/llimagej2c.cpp b/linden/indra/llimage/llimagej2c.cpp index 1b93c21..ed58f85 100644 --- a/linden/indra/llimage/llimagej2c.cpp +++ b/linden/indra/llimage/llimagej2c.cpp @@ -420,7 +420,7 @@ BOOL LLImageJ2C::loadAndValidate(const std::string &filename) S32 file_size = 0; LLAPRFile infile ; - infile.open(filename, LL_APR_RB, NULL, &file_size); + infile.open(filename, LL_APR_RB, LLAPRFile::global, &file_size); apr_file_t* apr_file = infile.getFileHandle() ; if (!apr_file) { diff --git a/linden/indra/llmessage/llcurl.cpp b/linden/indra/llmessage/llcurl.cpp index a4eb90d..811d4af 100644 --- a/linden/indra/llmessage/llcurl.cpp +++ b/linden/indra/llmessage/llcurl.cpp @@ -1002,7 +1002,7 @@ void LLCurl::initClass() S32 mutex_count = CRYPTO_num_locks(); for (S32 i=0; i= 0); LLAPRFile infile ; - infile.open(mThread->getLocalAPRFilePool(), mFileName, LL_APR_RB); + infile.open(mFileName, LL_APR_RB, LLAPRFile::local); if (!infile.getFileHandle()) { llwarns << "LLLFS: Unable to read file: " << mFileName << llendl; @@ -213,7 +209,7 @@ bool LLLFSThread::Request::processRequest() if (mOffset < 0) flags |= APR_APPEND; LLAPRFile outfile ; - outfile.open(mThread->getLocalAPRFilePool(), mFileName, flags); + outfile.open(mFileName, flags, LLAPRFile::local); if (!outfile.getFileHandle()) { llwarns << "LLLFS: Unable to write file: " << mFileName << llendl; diff --git a/linden/indra/llvfs/llvfs.cpp b/linden/indra/llvfs/llvfs.cpp index e5ffce4..7df2a81 100644 --- a/linden/indra/llvfs/llvfs.cpp +++ b/linden/indra/llvfs/llvfs.cpp @@ -2089,7 +2089,7 @@ void LLVFS::dumpFiles() llinfos << " Writing " << filename << llendl; LLAPRFile outfile ; - outfile.open(filename, LL_APR_WB); + outfile.open(filename, LL_APR_WB, LLAPRFile::global); outfile.write(buffer, size); outfile.close(); delete[] buffer; diff --git a/linden/indra/newview/llappviewer.cpp b/linden/indra/newview/llappviewer.cpp index a57050d..cdecaf4 100644 --- a/linden/indra/newview/llappviewer.cpp +++ b/linden/indra/newview/llappviewer.cpp @@ -2487,7 +2487,7 @@ void LLAppViewer::handleViewerCrash() llinfos << "Creating crash marker file " << crash_file_name << llendl; LLAPRFile crash_file ; - crash_file.open(crash_file_name, LL_APR_W); + crash_file.open(crash_file_name, LL_APR_W, LLAPRFile::local); if (crash_file.getFileHandle()) { LL_INFOS("MarkerFile") << "Created crash marker file " << crash_file_name << LL_ENDL; @@ -2555,11 +2555,11 @@ bool LLAppViewer::anotherInstanceRunning() LL_DEBUGS("MarkerFile") << "Checking marker file for lock..." << LL_ENDL; //Freeze case checks - if (LLAPRFile::isExist(marker_file, NULL, LL_APR_RB)) + if (LLAPRFile::isExist(marker_file, LL_APR_RB)) { // File exists, try opening with write permissions LLAPRFile outfile ; - outfile.open(marker_file, LL_APR_WB); + outfile.open(marker_file, LL_APR_WB, LLAPRFile::global); apr_file_t* fMarker = outfile.getFileHandle() ; if (!fMarker) { @@ -2599,24 +2599,24 @@ void LLAppViewer::initMarkerFile() std::string error_marker_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, ERROR_MARKER_FILE_NAME); - if (LLAPRFile::isExist(mMarkerFileName, NULL, LL_APR_RB) && !anotherInstanceRunning()) + if (LLAPRFile::isExist(mMarkerFileName, LL_APR_RB) && !anotherInstanceRunning()) { gLastExecEvent = LAST_EXEC_FROZE; LL_INFOS("MarkerFile") << "Exec marker found: program froze on previous execution" << LL_ENDL; } - if(LLAPRFile::isExist(logout_marker_file, NULL, LL_APR_RB)) + if(LLAPRFile::isExist(logout_marker_file, LL_APR_RB)) { LL_INFOS("MarkerFile") << "Last exec LLError crashed, setting LastExecEvent to " << LAST_EXEC_LLERROR_CRASH << LL_ENDL; gLastExecEvent = LAST_EXEC_LOGOUT_FROZE; } - if(LLAPRFile::isExist(llerror_marker_file, NULL, LL_APR_RB)) + if(LLAPRFile::isExist(llerror_marker_file, LL_APR_RB)) { llinfos << "Last exec LLError crashed, setting LastExecEvent to " << LAST_EXEC_LLERROR_CRASH << llendl; if(gLastExecEvent == LAST_EXEC_LOGOUT_FROZE) gLastExecEvent = LAST_EXEC_LOGOUT_CRASH; else gLastExecEvent = LAST_EXEC_LLERROR_CRASH; } - if(LLAPRFile::isExist(error_marker_file, NULL, LL_APR_RB)) + if(LLAPRFile::isExist(error_marker_file, LL_APR_RB)) { LL_INFOS("MarkerFile") << "Last exec crashed, setting LastExecEvent to " << LAST_EXEC_OTHER_CRASH << LL_ENDL; if(gLastExecEvent == LAST_EXEC_LOGOUT_FROZE) gLastExecEvent = LAST_EXEC_LOGOUT_CRASH; @@ -2635,7 +2635,7 @@ void LLAppViewer::initMarkerFile() // Create the marker file for this execution & lock it apr_status_t s; - s = mMarkerFile.open(mMarkerFileName, LL_APR_W, gAPRPoolp); + s = mMarkerFile.open(mMarkerFileName, LL_APR_W, LLAPRFile::global); if (s == APR_SUCCESS && mMarkerFile.getFileHandle()) { @@ -3716,7 +3716,7 @@ void LLAppViewer::sendLogoutRequest() mLogoutMarkerFileName = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,LOGOUT_MARKER_FILE_NAME); LLAPRFile outfile ; - outfile.open(mLogoutMarkerFileName, LL_APR_W); + outfile.open(mLogoutMarkerFileName, LL_APR_W, LLAPRFile::global); mLogoutMarkerFile = outfile.getFileHandle() ; if (mLogoutMarkerFile) { diff --git a/linden/indra/newview/llfloateranimpreview.cpp b/linden/indra/newview/llfloateranimpreview.cpp index 162456b..57ee161 100644 --- a/linden/indra/newview/llfloateranimpreview.cpp +++ b/linden/indra/newview/llfloateranimpreview.cpp @@ -238,7 +238,7 @@ BOOL LLFloaterAnimPreview::postBuild() S32 file_size; LLAPRFile infile ; - infile.open(mFilenameAndPath, LL_APR_RB, NULL, &file_size); + infile.open(mFilenameAndPath, LL_APR_RB, LLAPRFile::global, &file_size); if (!infile.getFileHandle()) { diff --git a/linden/indra/newview/lltexturecache.cpp b/linden/indra/newview/lltexturecache.cpp index 3b724e2..9c3bed2 100644 --- a/linden/indra/newview/lltexturecache.cpp +++ b/linden/indra/newview/lltexturecache.cpp @@ -175,7 +175,7 @@ private: bool LLTextureCacheLocalFileWorker::doRead() { - S32 local_size = LLAPRFile::size(mFileName, mCache->getLocalAPRFilePool()); + S32 local_size = LLAPRFile::size(mFileName); if (local_size > 0 && mFileName.size() > 4) { @@ -249,7 +249,7 @@ bool LLTextureCacheLocalFileWorker::doRead() } mReadData = new U8[mDataSize]; - S32 bytes_read = LLAPRFile::readEx(mFileName, mReadData, mOffset, mDataSize, mCache->getLocalAPRFilePool()); + S32 bytes_read = LLAPRFile::readEx(mFileName, mReadData, mOffset, mDataSize); if (bytes_read != mDataSize) { @@ -318,11 +318,11 @@ bool LLTextureCacheRemoteWorker::doRead() { std::string filename = mCache->getLocalFileName(mID); local_filename = filename + ".j2c"; - local_size = LLAPRFile::size(local_filename, mCache->getLocalAPRFilePool()); + local_size = LLAPRFile::size(local_filename); if (local_size == 0) { local_filename = filename + ".tga"; - local_size = LLAPRFile::size(local_filename, mCache->getLocalAPRFilePool()); + local_size = LLAPRFile::size(local_filename); if (local_size > 0) { mImageFormat = IMG_CODEC_TGA; @@ -390,8 +390,7 @@ bool LLTextureCacheRemoteWorker::doRead() mDataSize = local_size; } mReadData = new U8[mDataSize]; - S32 bytes_read = LLAPRFile::readEx(local_filename, - mReadData, mOffset, mDataSize, mCache->getLocalAPRFilePool()); + S32 bytes_read = LLAPRFile::readEx(local_filename, mReadData, mOffset, mDataSize); if (bytes_read != mDataSize) { // llwarns << "Error reading file from local cache: " << local_filename @@ -485,7 +484,7 @@ bool LLTextureCacheRemoteWorker::doRead() S32 size = TEXTURE_CACHE_ENTRY_SIZE - mOffset; mReadData = new U8[size]; S32 bytes_read = LLAPRFile::readEx(mCache->mHeaderDataFileName, - mReadData, offset, size, mCache->getLocalAPRFilePool()); + mReadData, offset, size); if (bytes_read != size) { // llwarns << "LLTextureCacheWorker: " << mID @@ -511,7 +510,7 @@ bool LLTextureCacheRemoteWorker::doRead() if (mFileHandle == LLLFSThread::nullHandle()) { std::string filename = mCache->getTextureFileName(mID); - S32 filesize = LLAPRFile::size(filename, mCache->getLocalAPRFilePool()); + S32 filesize = LLAPRFile::size(filename); if (filesize > mOffset) { S32 datasize = TEXTURE_CACHE_ENTRY_SIZE + filesize; @@ -570,7 +569,7 @@ bool LLTextureCacheRemoteWorker::doRead() } #else std::string filename = mCache->getTextureFileName(mID); - S32 filesize = LLAPRFile::size(filename, mCache->getLocalAPRFilePool()); + S32 filesize = LLAPRFile::size(filename); S32 bytes_read = 0; if (filesize > mOffset) { @@ -592,8 +591,7 @@ bool LLTextureCacheRemoteWorker::doRead() mReadData = data; bytes_read = LLAPRFile::readEx(filename, mReadData + data_offset, - file_offset, file_size, - mCache->getLocalAPRFilePool()); + file_offset, file_size); if (bytes_read != file_size) { // llwarns << "LLTextureCacheWorker: " << mID @@ -696,7 +694,7 @@ bool LLTextureCacheRemoteWorker::doWrite() llassert_always(mOffset < TEXTURE_CACHE_ENTRY_SIZE); S32 offset = idx * TEXTURE_CACHE_ENTRY_SIZE + mOffset; S32 size = TEXTURE_CACHE_ENTRY_SIZE - mOffset; - S32 bytes_written = LLAPRFile::writeEx(mCache->mHeaderDataFileName, mWriteData, offset, size, mCache->getLocalAPRFilePool()); + S32 bytes_written = LLAPRFile::writeEx(mCache->mHeaderDataFileName, mWriteData, offset, size); if (bytes_written <= 0) { @@ -774,8 +772,7 @@ bool LLTextureCacheRemoteWorker::doWrite() bytes_written = LLAPRFile::writeEx(filename, mWriteData + data_offset, - file_offset, file_size, - mCache->getLocalAPRFilePool()); + file_offset, file_size); if (bytes_written <= 0) { mDataSize = -1; // failed @@ -975,8 +972,7 @@ bool LLTextureCache::appendToTextureEntryList(const LLUUID& id, S32 bodysize) Entry* entry = new Entry(id, bodysize, time(NULL)); LLAPRFile::writeEx(mTexturesDirEntriesFileName, - (U8*)entry, -1, 1*sizeof(Entry), - getLocalAPRFilePool()); + (U8*)entry, -1, 1*sizeof(Entry)); delete entry; if (iter != mTexturesSizeMap.end()) { @@ -1024,8 +1020,8 @@ void LLTextureCache::purgeCache(ELLPath location) { setDirNames(location); - LLAPRFile::remove(mHeaderEntriesFileName, getLocalAPRFilePool()); - LLAPRFile::remove(mHeaderDataFileName, getLocalAPRFilePool()); + LLAPRFile::remove(mHeaderEntriesFileName); + LLAPRFile::remove(mHeaderDataFileName); } purgeAllTextures(true); } @@ -1092,11 +1088,10 @@ void LLTextureCache::readHeaderCache() LLMutexLock lock(&mHeaderMutex); mHeaderEntriesInfo.mVersion = 0.f; mHeaderEntriesInfo.mEntries = 0; - if (LLAPRFile::isExist(mHeaderEntriesFileName, getLocalAPRFilePool())) + if (LLAPRFile::isExist(mHeaderEntriesFileName)) { LLAPRFile::readEx(mHeaderEntriesFileName, - (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo), - getLocalAPRFilePool()); + (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo)); } if (mHeaderEntriesInfo.mVersion != sHeaderCacheVersion) { @@ -1106,8 +1101,7 @@ void LLTextureCache::readHeaderCache() mHeaderEntriesInfo.mVersion = sHeaderCacheVersion; LLAPRFile::writeEx(mHeaderEntriesFileName, - (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo), - getLocalAPRFilePool()); + (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo)); } } else @@ -1118,8 +1112,7 @@ void LLTextureCache::readHeaderCache() Entry* entries = new Entry[num_entries]; { LLAPRFile::readEx(mHeaderEntriesFileName, - (U8*)entries, sizeof(EntriesInfo), num_entries*sizeof(Entry), - getLocalAPRFilePool()); + (U8*)entries, sizeof(EntriesInfo), num_entries*sizeof(Entry)); } typedef std::set lru_set_t; lru_set_t lru; @@ -1165,7 +1158,7 @@ void LLTextureCache::purgeAllTextures(bool purge_directories) LLFile::rmdir(dirname); } } - LLAPRFile::remove(mTexturesDirEntriesFileName, getLocalAPRFilePool()); + LLAPRFile::remove(mTexturesDirEntriesFileName); if (purge_directories) { LLFile::rmdir(mTexturesDirName); @@ -1186,7 +1179,7 @@ void LLTextureCache::purgeTextures(bool validate) LLMutexLock lock(&mHeaderMutex); - S32 filesize = LLAPRFile::size(mTexturesDirEntriesFileName, getLocalAPRFilePool()); + S32 filesize = LLAPRFile::size(mTexturesDirEntriesFileName); S32 num_entries = filesize / sizeof(Entry); if (num_entries * (S32)sizeof(Entry) != filesize) { @@ -1201,8 +1194,7 @@ void LLTextureCache::purgeTextures(bool validate) Entry* entries = new Entry[num_entries]; S32 bytes_read = LLAPRFile::readEx(mTexturesDirEntriesFileName, - (U8*)entries, 0, num_entries*sizeof(Entry), - getLocalAPRFilePool()); + (U8*)entries, 0, num_entries*sizeof(Entry)); if (bytes_read != filesize) { LL_WARNS("TextureCache") << "Bad cache file (2): " << mTexturesDirEntriesFileName << " Purging." << LL_ENDL; @@ -1261,7 +1253,7 @@ void LLTextureCache::purgeTextures(bool validate) if (uuididx == validate_idx) { LL_DEBUGS("TextureCache") << "Validating: " << filename << "Size: " << entries[idx].mSize << LL_ENDL; - S32 bodysize = LLAPRFile::size(filename, getLocalAPRFilePool()); + S32 bodysize = LLAPRFile::size(filename); if (bodysize != entries[idx].mSize) { LL_WARNS("TextureCache") << "TEXTURE CACHE BODY HAS BAD SIZE: " << bodysize << " != " << entries[idx].mSize @@ -1295,10 +1287,9 @@ void LLTextureCache::purgeTextures(bool validate) << num_entries << " (" << num_entries*sizeof(Entry)/1024 << "KB)" << LL_ENDL; - LLAPRFile::remove(mTexturesDirEntriesFileName, getLocalAPRFilePool()); + LLAPRFile::remove(mTexturesDirEntriesFileName); LLAPRFile::writeEx(mTexturesDirEntriesFileName, - (U8*)&entries[0], 0, num_entries*sizeof(Entry), - getLocalAPRFilePool()); + (U8*)&entries[0], 0, num_entries*sizeof(Entry)); mTexturesSizeTotal = 0; mTexturesSizeMap.clear(); @@ -1345,7 +1336,7 @@ void LLTextureCache::purgeTextureFilesTimeSliced(BOOL force_all) for (LLTextureCache::filename_list_t::iterator iter = mFilesToDelete.begin(); iter!=mFilesToDelete.end(); ) { LLTextureCache::filename_list_t::iterator iter2 = iter++; - LLAPRFile::remove(*iter2, NULL); + LLAPRFile::remove(*iter2); mFilesToDelete.erase(iter2); howmany++; @@ -1416,8 +1407,7 @@ S32 LLTextureCache::getHeaderCacheEntry(const LLUUID& id, bool touch, S32* image mHeaderIDMap[id] = idx; // Update Info LLAPRFile::writeEx(mHeaderEntriesFileName, - (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo), - getLocalAPRFilePool()); + (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo)); } else if (!mLRU.empty()) { @@ -1443,8 +1433,7 @@ S32 LLTextureCache::getHeaderCacheEntry(const LLUUID& id, bool touch, S32* image Entry* entry = new Entry(id, *imagesize, time(NULL)); S32 offset = sizeof(EntriesInfo) + idx * sizeof(Entry); LLAPRFile::writeEx(mHeaderEntriesFileName, - (U8*)entry, offset, sizeof(Entry), - getLocalAPRFilePool()); + (U8*)entry, offset, sizeof(Entry)); delete entry; } else if (imagesize) @@ -1454,8 +1443,7 @@ S32 LLTextureCache::getHeaderCacheEntry(const LLUUID& id, bool touch, S32* image S32 offset = sizeof(EntriesInfo) + idx * sizeof(Entry); LLAPRFile::readEx(mHeaderEntriesFileName, - (U8*)&entry, offset, sizeof(Entry), - getLocalAPRFilePool()); + (U8*)&entry, offset, sizeof(Entry)); *imagesize = entry.mSize; } } @@ -1608,8 +1596,7 @@ bool LLTextureCache::removeHeaderCacheEntry(const LLUUID& id) S32 offset = sizeof(EntriesInfo) + idx * sizeof(Entry); LLAPRFile::writeEx(mHeaderEntriesFileName, - (U8*)entry, offset, sizeof(Entry), - getLocalAPRFilePool()); + (U8*)entry, offset, sizeof(Entry)); delete entry; mLRU[idx] = id; mHeaderIDMap.erase(id); @@ -1626,7 +1613,7 @@ void LLTextureCache::removeFromCache(const LLUUID& id) if (!mReadOnly) { removeHeaderCacheEntry(id); - LLAPRFile::remove(getTextureFileName(id), getLocalAPRFilePool()); + LLAPRFile::remove(getTextureFileName(id)); } } diff --git a/linden/indra/newview/llviewermenufile.cpp b/linden/indra/newview/llviewermenufile.cpp index 178fc97..3283391 100644 --- a/linden/indra/newview/llviewermenufile.cpp +++ b/linden/indra/newview/llviewermenufile.cpp @@ -798,7 +798,7 @@ void upload_new_resource(const std::string& src_filename, std::string name, // copy this file into the vfs for upload S32 file_size; LLAPRFile infile ; - infile.open(filename, LL_APR_RB, NULL, &file_size); + infile.open(filename, LL_APR_RB, LLAPRFile::local, &file_size); if (infile.getFileHandle()) { LLVFile file(gVFS, uuid, asset_type, LLVFile::WRITE); diff --git a/linden/indra/newview/llvoavatar.cpp b/linden/indra/newview/llvoavatar.cpp index c361f49..ab5d83e 100644 --- a/linden/indra/newview/llvoavatar.cpp +++ b/linden/indra/newview/llvoavatar.cpp @@ -8545,7 +8545,7 @@ void LLVOAvatar::dumpArchetypeXML( void* ) { LLVOAvatar* avatar = gAgent.getAvatarObject(); LLAPRFile outfile ; - outfile.open(gDirUtilp->getExpandedFilename(LL_PATH_CHARACTER,"new archetype.xml"), LL_APR_WB ); + outfile.open(gDirUtilp->getExpandedFilename(LL_PATH_CHARACTER,"new archetype.xml"), LL_APR_WB, LLAPRFile::global); apr_file_t* file = outfile.getFileHandle() ; if( !file ) { diff --git a/linden/indra/newview/primbackup.cpp b/linden/indra/newview/primbackup.cpp index 4e0e56f..4f93ddf 100644 --- a/linden/indra/newview/primbackup.cpp +++ b/linden/indra/newview/primbackup.cpp @@ -1072,7 +1072,7 @@ void primbackup::upload_next_asset() S32 file_size; apr_file_t* fp; LLAPRFile aFile; - aFile.open(filename, LL_APR_RB, NULL, &file_size); + aFile.open(filename, LL_APR_RB, LLAPRFile::global, &file_size); fp = aFile.getFileHandle(); if (fp) { -- cgit v1.1