"Ken Kozman" <[EMAIL PROTECTED]> writes:
> 
> I also noticed when running around the standard NS_IMPL_ADDREF and RELEASE
> macros that they do not do a thread safe increment and decrement on the
> internal ref count. For example:
> 
> #define NS_IMPL_ADDREF(_class)                               \
> NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void)                \
> {                                                            \
>   NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");  \
>   NS_ASSERT_OWNINGTHREAD(_class);                            \
>   ++mRefCnt;                                                 \
>   NS_LOG_ADDREF(this, mRefCnt, #_class, sizeof(*this));      \
>   return mRefCnt;                                            \
> }
> 
> Now I do not know what sort of multi threaded stuff is allowed or intended
> for XPCOM, but again under COM this would be a big no-no unless you were
> implementing purely single-threaded objects. Maybe this is the case for most
> of the XPCOM stuff, but it surprises me that there is an
> NS_ASSERT_OWNINGTHREAD( ) call, and then it does not bother to do safe
> increments and decrements (but I'm probably missing something here...)

Classes that are suitably threadsafe should use
NS_IMPL_THREADSAFE_ISUPPORTSx, where x is the number of interfaces
implemented.  This will pull in threadsafe implementations of AddRef,
Release, etc.

Dan

Reply via email to