diff options
author | Monty Brandenberg <monty@lindenlab.com> | 2012-06-12 12:41:09 -0400 |
---|---|---|
committer | Monty Brandenberg <monty@lindenlab.com> | 2012-06-12 12:41:09 -0400 |
commit | 24e16e1632974057013b86300bb60954ea6f5684 (patch) | |
tree | 09fccb4bcbf24721129e1d01bdb2e3337cd9ccc2 | |
parent | 75242eab8f8a892c792681fca080d86cfbb3e061 (diff) |
Convert _refcounted.h over to using LLAtomic32<>.
Beware of bad documentation. operator--(int) does not return what
the header claimed it did.
-rw-r--r-- | indra/llcommon/llapr.h | 2 | ||||
-rw-r--r-- | indra/llcorehttp/_refcounted.h | 52 | ||||
-rw-r--r-- | indra/llcorehttp/bufferarray.cpp | 6 |
3 files changed, 22 insertions, 38 deletions
diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index af33ce666f..034546c3f3 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -168,7 +168,7 @@ public: void operator -=(Type x) { apr_atomic_sub32(&mData, apr_uint32_t(x)); } void operator +=(Type x) { apr_atomic_add32(&mData, apr_uint32_t(x)); } Type operator ++(int) { return apr_atomic_inc32(&mData); } // Type++ - Type operator --(int) { return apr_atomic_dec32(&mData); } // Type-- + Type operator --(int) { return apr_atomic_dec32(&mData); } // approximately --Type (0 if final is 0, non-zero otherwise) private: apr_uint32_t mData; diff --git a/indra/llcorehttp/_refcounted.h b/indra/llcorehttp/_refcounted.h index 72cef6b342..a96c65fb6b 100644 --- a/indra/llcorehttp/_refcounted.h +++ b/indra/llcorehttp/_refcounted.h @@ -28,9 +28,11 @@ #define LLCOREINT__REFCOUNTED_H_ +#include "linden_common.h" + #include <boost/thread.hpp> -#include "linden_common.h" +#include "llapr.h" namespace LLCoreInt @@ -44,7 +46,7 @@ private: void operator=(const RefCounted &); // Not defined public: - explicit RefCounted(bool const implicit) + explicit RefCounted(bool const implicit) : mRefCount(implicit) {} @@ -52,42 +54,34 @@ public: void addRef() const; void release() const; bool isLastRef() const; - int getRefCount() const; + S32 getRefCount() const; void noRef() const; - static const int NOT_REF_COUNTED = -1; + static const S32 NOT_REF_COUNTED = -1; protected: virtual ~RefCounted(); virtual void destroySelf(); private: - mutable int mRefCount; - mutable boost::mutex mRefLock; + mutable LLAtomicS32 mRefCount; }; // end class RefCounted inline void RefCounted::addRef() const { - boost::mutex::scoped_lock lock(mRefLock); - llassert_always(mRefCount >= 0); - ++mRefCount; + S32 count(mRefCount++); + llassert_always(count >= 0); } inline void RefCounted::release() const { - int count(0); - { - // CRITICAL SECTION - boost::mutex::scoped_lock lock(mRefLock); - llassert_always(mRefCount != NOT_REF_COUNTED); - llassert_always(mRefCount > 0); - count = --mRefCount; - // CRITICAL SECTION - } - + S32 count(mRefCount); + llassert_always(count != NOT_REF_COUNTED); + llassert_always(count > 0); + count = mRefCount--; // clean ourselves up if that was the last reference if (0 == count) @@ -99,32 +93,22 @@ inline void RefCounted::release() const inline bool RefCounted::isLastRef() const { - int count(0); - { - // CRITICAL SECTION - boost::mutex::scoped_lock lock(mRefLock); - - llassert_always(mRefCount != NOT_REF_COUNTED); - llassert_always(mRefCount >= 1); - count = mRefCount; - // CRITICAL SECTION - } - + const S32 count(mRefCount); + llassert_always(count != NOT_REF_COUNTED); + llassert_always(count >= 1); return (1 == count); } -inline int RefCounted::getRefCount() const +inline S32 RefCounted::getRefCount() const { - boost::mutex::scoped_lock lock(mRefLock); - const int result(mRefCount); + const S32 result(mRefCount); return result; } inline void RefCounted::noRef() const { - boost::mutex::scoped_lock lock(mRefLock); llassert_always(mRefCount <= 1); mRefCount = NOT_REF_COUNTED; } diff --git a/indra/llcorehttp/bufferarray.cpp b/indra/llcorehttp/bufferarray.cpp index 6d5309a043..ae92057df0 100644 --- a/indra/llcorehttp/bufferarray.cpp +++ b/indra/llcorehttp/bufferarray.cpp @@ -175,7 +175,7 @@ size_t BufferArray::read(size_t pos, void * dst, size_t len) if (pos >= mLen) return 0; size_t len_limit(mLen - pos); - len = std::min(len, len_limit); + len = (std::min)(len, len_limit); if (0 == len) return 0; @@ -189,7 +189,7 @@ size_t BufferArray::read(size_t pos, void * dst, size_t len) { Block & block(*mBlocks[block_start]); size_t block_limit(block.mUsed - offset); - size_t block_len(std::min(block_limit, len)); + size_t block_len((std::min)(block_limit, len)); memcpy(c_dst, &block.mData[offset], block_len); result += block_len; @@ -223,7 +223,7 @@ size_t BufferArray::write(size_t pos, const void * src, size_t len) { Block & block(*mBlocks[block_start]); size_t block_limit(block.mUsed - offset); - size_t block_len(std::min(block_limit, len)); + size_t block_len((std::min)(block_limit, len)); memcpy(&block.mData[offset], c_src, block_len); result += block_len; |