diff options
author | Richard Linden <none@none> | 2013-01-08 00:25:07 -0800 |
---|---|---|
committer | Richard Linden <none@none> | 2013-01-08 00:25:07 -0800 |
commit | 3c341a11ab7b8f3fd18afcf3f50af6dfafa632c2 (patch) | |
tree | c937cdcd5368a2b4665d06a1af047eebddd31737 | |
parent | 68413515029f50713c70e4adec3ce6fd1022d59f (diff) |
SH-3468 WIP add memory tracking base class
more fixes for unit test crashes
added llcommon initialization/teardown for unit tests
that indirectly trigger lltrace
changed access of atomic refcount to use preincrement/decrement
operators to reflect desired semantics
always call apr_initialize in LLCommon::initClass, even
if already initialized...apr does internal reference counting
to keep things straight
-rw-r--r-- | indra/llcommon/llapr.cpp | 19 | ||||
-rw-r--r-- | indra/llcommon/llapr.h | 5 | ||||
-rw-r--r-- | indra/llcommon/llmutex.cpp | 11 | ||||
-rw-r--r-- | indra/llcorehttp/_refcounted.h | 4 | ||||
-rw-r--r-- | indra/llmessage/llproxy.cpp | 7 | ||||
-rw-r--r-- | indra/test/io.cpp | 11 | ||||
-rw-r--r-- | indra/test/llhttpdate_tut.cpp | 9 | ||||
-rw-r--r-- | indra/test/lliohttpserver_tut.cpp | 7 | ||||
-rw-r--r-- | indra/test/test.cpp | 2 |
9 files changed, 60 insertions, 15 deletions
diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index 8a87911315..0556fadb26 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -38,12 +38,15 @@ apr_thread_mutex_t *gCallStacksLogMutexp = NULL; const S32 FULL_VOLATILE_APR_POOL = 1024 ; //number of references to LLVolatileAPRPool +bool gAPRInitialized = false; + void ll_init_apr() { + // Initialize APR and create the global pool + apr_initialize(); + if (!gAPRPoolp) { - // Initialize APR and create the global pool - apr_initialize(); apr_pool_create(&gAPRPoolp, NULL); // Initialize the logging mutex @@ -57,11 +60,19 @@ void ll_init_apr() } LLThreadLocalPointerBase::initAllThreadLocalStorage(); + gAPRInitialized = true; } -void ll_cleanup_apr(bool destroy_pools) +bool ll_apr_is_initialized() +{ + return gAPRInitialized; +} + +void ll_cleanup_apr() { + gAPRInitialized = false; + LL_INFOS("APR") << "Cleaning up APR" << LL_ENDL; if (gLogMutexp) @@ -83,7 +94,7 @@ void ll_cleanup_apr(bool destroy_pools) LLThreadLocalPointerBase::destroyAllThreadLocalStorage(); - if (gAPRPoolp && destroy_pools) + if (gAPRPoolp) { apr_pool_destroy(gAPRPoolp); gAPRPoolp = NULL; diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index 424ddc6505..3b65c0dc34 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -70,7 +70,10 @@ void LL_COMMON_API ll_init_apr(); /** * @brief Cleanup those common apr constructs. */ -void LL_COMMON_API ll_cleanup_apr(bool destroy_pools = true); +void LL_COMMON_API ll_cleanup_apr(); + +bool LL_COMMON_API ll_apr_is_initialized(); + // //LL apr_pool diff --git a/indra/llcommon/llmutex.cpp b/indra/llcommon/llmutex.cpp index b685bb4d60..ad0287c6d5 100644 --- a/indra/llcommon/llmutex.cpp +++ b/indra/llcommon/llmutex.cpp @@ -56,12 +56,15 @@ LLMutex::~LLMutex() //bad assertion, the subclass LLSignal might be "locked", and that's OK //llassert_always(!isLocked()); // better not be locked! #endif - apr_thread_mutex_destroy(mAPRMutexp); - mAPRMutexp = NULL; - if (mIsLocalPool) + if (ll_apr_is_initialized()) { - apr_pool_destroy(mAPRPoolp); + apr_thread_mutex_destroy(mAPRMutexp); + if (mIsLocalPool) + { + apr_pool_destroy(mAPRPoolp); + } } + mAPRMutexp = NULL; } diff --git a/indra/llcorehttp/_refcounted.h b/indra/llcorehttp/_refcounted.h index 21a916b13b..402e725152 100644 --- a/indra/llcorehttp/_refcounted.h +++ b/indra/llcorehttp/_refcounted.h @@ -72,7 +72,7 @@ private: inline void RefCounted::addRef() const { - S32 count(mRefCount++); + S32 count(++mRefCount); llassert_always(count >= 0); } @@ -82,7 +82,7 @@ inline void RefCounted::release() const S32 count(mRefCount); llassert_always(count != NOT_REF_COUNTED); llassert_always(count > 0); - count = mRefCount--; + count = --mRefCount; // clean ourselves up if that was the last reference if (0 == count) diff --git a/indra/llmessage/llproxy.cpp b/indra/llmessage/llproxy.cpp index aa474fabd2..9b8d19cc3e 100644 --- a/indra/llmessage/llproxy.cpp +++ b/indra/llmessage/llproxy.cpp @@ -61,8 +61,11 @@ LLProxy::LLProxy(): LLProxy::~LLProxy() { - stopSOCKSProxy(); - disableHTTPProxy(); + if (ll_apr_is_initialized()) + { + stopSOCKSProxy(); + disableHTTPProxy(); + } } /** diff --git a/indra/test/io.cpp b/indra/test/io.cpp index ce747f667d..f2b4a5339c 100644 --- a/indra/test/io.cpp +++ b/indra/test/io.cpp @@ -44,6 +44,7 @@ #include "llsdrpcclient.h" #include "llsdrpcserver.h" #include "llsdserialize.h" +#include "llcommon.h" #include "lluuid.h" #include "llinstantmessage.h" @@ -830,6 +831,7 @@ namespace tut public: PumpAndChainTestData() { + LLCommon::initClass(); apr_pool_create(&mPool, NULL); mPump = new LLPumpIO(mPool); } @@ -839,6 +841,7 @@ namespace tut mChain.clear(); delete mPump; apr_pool_destroy(mPool); + LLCommon::cleanupClass(); } }; typedef test_group<PumpAndChainTestData> PumpAndChainTestGroup; @@ -909,6 +912,7 @@ namespace tut pipe_and_pump_fitness() { + LLCommon::initClass(); LLFrameTimer::updateFrameTime(); apr_pool_create(&mPool, NULL); mPump = new LLPumpIO(mPool); @@ -923,6 +927,7 @@ namespace tut mSocket.reset(); delete mPump; apr_pool_destroy(mPool); + LLCommon::cleanupClass(); } protected: @@ -1186,8 +1191,12 @@ namespace tut LLSimpleRPCResponse(LLSD* response) : mResponsePtr(response) { + LLCommon::initClass(); + } + ~LLSimpleRPCResponse() + { + LLCommon::cleanupClass(); } - ~LLSimpleRPCResponse() {} virtual bool response(LLPumpIO* pump) { *mResponsePtr = mReturnValue; diff --git a/indra/test/llhttpdate_tut.cpp b/indra/test/llhttpdate_tut.cpp index 46684bb9dc..d6f0ba5e66 100644 --- a/indra/test/llhttpdate_tut.cpp +++ b/indra/test/llhttpdate_tut.cpp @@ -29,6 +29,7 @@ #include "lltut.h" #include "lldate.h" +#include "llcommon.h" #include "llframetimer.h" #include <time.h> @@ -38,6 +39,14 @@ namespace tut { struct httpdate_data { + httpdate_data() + { + LLCommon::initClass(); + } + ~httpdate_data() + { + LLCommon::cleanupClass(); + } LLDate some_date; }; typedef test_group<httpdate_data> httpdate_test; diff --git a/indra/test/lliohttpserver_tut.cpp b/indra/test/lliohttpserver_tut.cpp index 2fdc455f45..e7af09f80b 100644 --- a/indra/test/lliohttpserver_tut.cpp +++ b/indra/test/lliohttpserver_tut.cpp @@ -31,6 +31,7 @@ #include "lliohttpserver.h" #include "llsdhttpserver.h" #include "llsdserialize.h" +#include "llcommon.h" #include "llpipeutil.h" @@ -76,11 +77,17 @@ namespace tut HTTPServiceTestData() : mResponse(NULL) { + LLCommon::initClass(); LLHTTPStandardServices::useServices(); LLHTTPRegistrar::buildAllServices(mRoot); mRoot.addNode("/delayed/echo", new DelayedEcho(this)); mRoot.addNode("/wire/hello", new LLHTTPNodeForPipe<WireHello>); } + + ~HTTPServiceTestData() + { + LLCommon::cleanupClass(); + } LLHTTPNode mRoot; LLHTTPNode::ResponsePtr mResponse; diff --git a/indra/test/test.cpp b/indra/test/test.cpp index d75040393c..8bd302ce7a 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -643,7 +643,7 @@ int main(int argc, char **argv) s.close(); } - ll_cleanup_apr(false); + ll_cleanup_apr(); int retval = (success ? 0 : 1); return retval; |