diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h
index af33ce666f1558193d3d2818cf0c3a5e98d6ee7a..034546c3f39f669e10566b80231cbb83a5596f68 100644
--- a/indra/llcommon/llapr.h
+++ b/indra/llcommon/llapr.h
@@ -168,7 +168,7 @@ template <typename Type> class LLAtomic32
 	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 72cef6b34209724b67fec26635ce4606a577184a..a96c65fb6b90a6b7c6de2e746f056eff323a2432 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 @@ class RefCounted
 	void operator=(const RefCounted &);			// Not defined
 	
 public:
-	explicit RefCounted(bool const implicit) 
+	explicit RefCounted(bool const implicit)
 		: mRefCount(implicit)
 		{}
 
@@ -52,42 +54,34 @@ class RefCounted
 	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 6d5309a043024c61c71e57c64449fe3df74249ba..ae92057df09d70cedfc316f528a25c09482e9146 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;