Bug 551298, patch A: Move THEBES_INLINE_DECL_REFCOUNTING to xpcom (with s/THEBES/NS/). r=bsmedberg

This commit is contained in:
Daniel Holbert 2010-04-01 08:07:23 -07:00
parent 5732abd0d7
commit 9d9224d62d
3 changed files with 34 additions and 23 deletions

View File

@ -98,27 +98,7 @@ enum gfxBreakPriority {
#include "nsAutoPtr.h"
#define THEBES_INLINE_DECL_REFCOUNTING(_class) \
public: \
nsrefcnt AddRef(void) { \
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt"); \
++mRefCnt; \
NS_LOG_ADDREF(this, mRefCnt, #_class, sizeof(*this)); \
return mRefCnt; \
} \
nsrefcnt Release(void) { \
NS_PRECONDITION(0 != mRefCnt, "dup release"); \
--mRefCnt; \
NS_LOG_RELEASE(this, mRefCnt, #_class); \
if (mRefCnt == 0) { \
mRefCnt = 1; /* stabilize */ \
NS_DELETEXPCOM(this); \
return 0; \
} \
return mRefCnt; \
} \
protected: \
nsAutoRefCnt mRefCnt; \
public:
NS_INLINE_DECL_REFCOUNTING(_class)
#define THEBES_INLINE_DECL_THREADSAFE_REFCOUNTING(_class) \
public: \

View File

@ -303,6 +303,35 @@ public:
*/
#define NS_INIT_ISUPPORTS() ((void)0)
/**
* Use this macro to declare and implement the AddRef & Release methods for a
* given non-XPCOM <i>_class</i>.
*
* The implementations here should match NS_IMPL_ADDREF/NS_IMPL_RELEASE, minus
* the nsrefcnt return-value and the NS_ASSERT_OWNINGTHREAD() call.
*
* @param _class The name of the class implementing the method
*/
#define NS_INLINE_DECL_REFCOUNTING(_class) \
public: \
void AddRef(void) { \
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt"); \
++mRefCnt; \
NS_LOG_ADDREF(this, mRefCnt, #_class, sizeof(*this)); \
} \
void Release(void) { \
NS_PRECONDITION(0 != mRefCnt, "dup release"); \
--mRefCnt; \
NS_LOG_RELEASE(this, mRefCnt, #_class); \
if (mRefCnt == 0) { \
mRefCnt = 1; /* stabilize */ \
NS_DELETEXPCOM(this); \
} \
} \
protected: \
nsAutoRefCnt mRefCnt; \
public:
/**
* Use this macro to implement the AddRef method for a given <i>_class</i>
* @param _class The name of the class implementing the method

View File

@ -108,10 +108,12 @@ extern "C++" {
// yet still denies you the ability to |AddRef()| an |nsCOMPtr|.
template <class T>
inline
nsrefcnt
void
ns_if_addref( T expr )
{
return expr ? expr->AddRef() : 0;
if (expr) {
expr->AddRef();
}
}
} /* extern "C++" */