diff options
author | Richard Linden <none@none> | 2013-10-01 14:28:39 -0700 |
---|---|---|
committer | Richard Linden <none@none> | 2013-10-01 14:28:39 -0700 |
commit | 59628d6f85deed89cb35d9343183069cfccd13c0 (patch) | |
tree | 6b4c35053c2291fd5ff1cccedf86bbd76ce78e1d /indra/llcommon/llrefcount.h | |
parent | ad777b46d0fe5d790e43efb1771e9f64f3ad3dfb (diff) | |
parent | 9e486f6c6abbee6cb41ba9a6271d8a025ad924ef (diff) |
Automated merge with http://bitbucket.org/lindenlab/viewer-release
Diffstat (limited to 'indra/llcommon/llrefcount.h')
-rwxr-xr-x | indra/llcommon/llrefcount.h | 87 |
1 files changed, 83 insertions, 4 deletions
diff --git a/indra/llcommon/llrefcount.h b/indra/llcommon/llrefcount.h index 32ae15435a..3d59e48f74 100755 --- a/indra/llcommon/llrefcount.h +++ b/indra/llcommon/llrefcount.h @@ -28,6 +28,7 @@ #include <boost/noncopyable.hpp> #include <boost/intrusive_ptr.hpp> +#include "llmutex.h" #define LL_REF_COUNT_DEBUG 0 #if LL_REF_COUNT_DEBUG @@ -61,7 +62,7 @@ public: inline S32 unref() const { llassert(mRef >= 1); - if (0 == --mRef) + if (0 == --mRef) { delete this; return 0; @@ -87,22 +88,100 @@ private: #endif }; + +//============================================================================ + +// see llmemory.h for LLPointer<> definition + +class LL_COMMON_API LLThreadSafeRefCount +{ +public: + static void initThreadSafeRefCount(); // creates sMutex + static void cleanupThreadSafeRefCount(); // destroys sMutex + +private: + static LLMutex* sMutex; + +protected: + virtual ~LLThreadSafeRefCount(); // use unref() + +public: + LLThreadSafeRefCount(); + LLThreadSafeRefCount(const LLThreadSafeRefCount&); + LLThreadSafeRefCount& operator=(const LLThreadSafeRefCount& ref) + { + if (sMutex) + { + sMutex->lock(); + } + mRef = 0; + if (sMutex) + { + sMutex->unlock(); + } + return *this; + } + + void ref() + { + if (sMutex) sMutex->lock(); + mRef++; + if (sMutex) sMutex->unlock(); + } + + S32 unref() + { + llassert(mRef >= 1); + if (sMutex) sMutex->lock(); + S32 res = --mRef; + if (sMutex) sMutex->unlock(); + if (0 == res) + { + delete this; + return 0; + } + return res; + } + S32 getNumRefs() const + { + return mRef; + } + +private: + S32 mRef; +}; + /** * intrusive pointer support * this allows you to use boost::intrusive_ptr with any LLRefCount-derived type */ +/** + * intrusive pointer support for LLThreadSafeRefCount + * this allows you to use boost::intrusive_ptr with any LLThreadSafeRefCount-derived type + */ namespace boost { - inline void intrusive_ptr_add_ref(LLRefCount* p) + inline void intrusive_ptr_add_ref(LLThreadSafeRefCount* p) { p->ref(); } - inline void intrusive_ptr_release(LLRefCount* p) + inline void intrusive_ptr_release(LLThreadSafeRefCount* p) { - p->unref(); + p->unref(); + } + + inline void intrusive_ptr_add_ref(LLRefCount* p) + { + p->ref(); + } + + inline void intrusive_ptr_release(LLRefCount* p) + { + p->unref(); } }; + #endif |