2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-08-17 10:25:41 -07:00
|
|
|
|
|
|
|
#ifndef nsAtomicRefcnt_h__
|
|
|
|
#define nsAtomicRefcnt_h__
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "pratom.h"
|
|
|
|
|
|
|
|
class nsAutoRefCnt;
|
|
|
|
|
|
|
|
// This header defines functions for modifying refcounts which wrap the
|
|
|
|
// PR_ATOMIC_* macros.
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
|
|
|
|
#if PR_BYTES_PER_LONG == 4
|
|
|
|
typedef volatile long nsAtomicRefcnt;
|
|
|
|
#else
|
|
|
|
#error "Windows should have 4 bytes per long."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else /* !defined(XP_WIN) */
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
typedef int32_t nsAtomicRefcnt;
|
2010-08-17 10:25:41 -07:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
inline int32_t
|
|
|
|
NS_AtomicIncrementRefcnt(int32_t &refcnt)
|
2011-03-28 12:58:49 -07:00
|
|
|
{
|
|
|
|
return PR_ATOMIC_INCREMENT(&refcnt);
|
|
|
|
}
|
|
|
|
|
2010-08-17 10:25:41 -07:00
|
|
|
inline nsrefcnt
|
|
|
|
NS_AtomicIncrementRefcnt(nsrefcnt &refcnt)
|
|
|
|
{
|
|
|
|
return (nsrefcnt) PR_ATOMIC_INCREMENT((nsAtomicRefcnt*)&refcnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsrefcnt
|
|
|
|
NS_AtomicIncrementRefcnt(nsAutoRefCnt &refcnt)
|
|
|
|
{
|
|
|
|
// This cast is safe since nsAtomicRefCnt contains just one member, its refcount.
|
|
|
|
return (nsrefcnt) PR_ATOMIC_INCREMENT((nsAtomicRefcnt*)&refcnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsrefcnt
|
|
|
|
NS_AtomicDecrementRefcnt(nsrefcnt &refcnt)
|
|
|
|
{
|
|
|
|
return (nsrefcnt) PR_ATOMIC_DECREMENT((nsAtomicRefcnt*)&refcnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsrefcnt
|
|
|
|
NS_AtomicDecrementRefcnt(nsAutoRefCnt &refcnt)
|
|
|
|
{
|
|
|
|
return (nsrefcnt) PR_ATOMIC_DECREMENT((nsAtomicRefcnt*)&refcnt);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
inline int32_t
|
|
|
|
NS_AtomicDecrementRefcnt(int32_t &refcnt)
|
2011-03-28 12:58:49 -07:00
|
|
|
{
|
|
|
|
return PR_ATOMIC_DECREMENT(&refcnt);
|
|
|
|
}
|
|
|
|
|
2010-08-17 10:25:41 -07:00
|
|
|
#endif
|