diff options
author | Oz Linden <oz@lindenlab.com> | 2013-10-03 18:04:27 -0400 |
---|---|---|
committer | Oz Linden <oz@lindenlab.com> | 2013-10-03 18:04:27 -0400 |
commit | 4dccf30bf318649c7b371355fd34cde6c143e867 (patch) | |
tree | 4acbdefe0bb187a817583e835112f4317e11d596 /indra/llcommon/llthread.h | |
parent | bd18f3c097304504c398df02613229a64f7eac81 (diff) | |
parent | f7158bc5afcec1da8b9d2d5a4ed86921e62d4959 (diff) |
merge changes for 3.6.7-release
Diffstat (limited to 'indra/llcommon/llthread.h')
-rwxr-xr-x | indra/llcommon/llthread.h | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index 0fb89c5613..f51d985b5f 100755 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -242,49 +242,39 @@ public: 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() + void unref() { llassert(mRef >= 1); - if (sMutex) sMutex->lock(); - S32 res = --mRef; - if (sMutex) sMutex->unlock(); - if (0 == res) - { - delete this; - return 0; + if ((--mRef) == 0) // See note in llapr.h on atomic decrement operator return value. + { + // If we hit zero, the caller should be the only smart pointer owning the object and we can delete it. + // It is technically possible for a vanilla pointer to mess this up, or another thread to + // jump in, find this object, create another smart pointer and end up dangling, but if + // the code is that bad and not thread-safe, it's trouble already. + delete this; } - return res; - } + } + S32 getNumRefs() const { - return mRef; + const S32 currentVal = mRef.CurrentValue(); + return currentVal; } private: - S32 mRef; + LLAtomic32< S32 > mRef; }; + /** * intrusive pointer support for LLThreadSafeRefCount * this allows you to use boost::intrusive_ptr with any LLThreadSafeRefCount-derived type @@ -315,4 +305,6 @@ public: //============================================================================ +extern LL_COMMON_API void assert_main_thread(); + #endif // LL_LLTHREAD_H |