Skip to content
Snippets Groups Projects
Commit e5b51c7f authored by Richard Linden's avatar Richard Linden
Browse files

BUIDLFIX: moved LLThreadSafeRefCount to proper file

parent 075a7bcc
No related branches found
No related tags found
No related merge requests found
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#define LL_EVENT_H #define LL_EVENT_H
#include "llsd.h" #include "llsd.h"
#include "llrefcount.h"
#include "llpointer.h" #include "llpointer.h"
namespace LLOldEvents namespace LLOldEvents
......
...@@ -214,82 +214,4 @@ class LLCopyOnWritePointer : public LLPointer<Type> ...@@ -214,82 +214,4 @@ class LLCopyOnWritePointer : public LLPointer<Type>
bool mStayUnique; bool mStayUnique;
}; };
//============================================================================
// 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 for LLThreadSafeRefCount
* this allows you to use boost::intrusive_ptr with any LLThreadSafeRefCount-derived type
*/
namespace boost
{
inline void intrusive_ptr_add_ref(LLThreadSafeRefCount* p)
{
p->ref();
}
inline void intrusive_ptr_release(LLThreadSafeRefCount* p)
{
p->unref();
}
};
#endif #endif
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/intrusive_ptr.hpp> #include <boost/intrusive_ptr.hpp>
#include "llmutex.h"
#define LL_REF_COUNT_DEBUG 0 #define LL_REF_COUNT_DEBUG 0
#if LL_REF_COUNT_DEBUG #if LL_REF_COUNT_DEBUG
...@@ -87,22 +88,100 @@ class LL_COMMON_API LLRefCount ...@@ -87,22 +88,100 @@ class LL_COMMON_API LLRefCount
#endif #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 * intrusive pointer support
* this allows you to use boost::intrusive_ptr with any LLRefCount-derived type * 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 namespace boost
{ {
inline void intrusive_ptr_add_ref(LLRefCount* p) inline void intrusive_ptr_add_ref(LLThreadSafeRefCount* p)
{ {
p->ref(); 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 #endif
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "apr_thread_cond.h" #include "apr_thread_cond.h"
#include "boost/intrusive_ptr.hpp" #include "boost/intrusive_ptr.hpp"
#include "llmutex.h" #include "llmutex.h"
#include "llpointer.h" #include "llrefcount.h"
LL_COMMON_API void assert_main_thread(); LL_COMMON_API void assert_main_thread();
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <map> #include <map>
#include "indra_constants.h" #include "indra_constants.h"
#include "llrefcount.h"
#include "llpointer.h" #include "llpointer.h"
#include "llstring.h" #include "llstring.h"
#include "llstringtable.h" #include "llstringtable.h"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment