2003-08-05 09:29:10 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2003-08-05 09:29:10 +04:00
|
|
|
#ifndef nsTraceRefcnt_h___
|
|
|
|
#define nsTraceRefcnt_h___
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
#include "nsXPCOM.h"
|
2003-08-05 09:29:10 +04:00
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
|
|
|
|
#define NS_LOG_ADDREF(_p, _rc, _type, _size) \
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_LogAddRef((_p), (_rc), (_type), (uint32_t) (_size))
|
2003-08-05 09:29:10 +04:00
|
|
|
|
|
|
|
#define NS_LOG_RELEASE(_p, _rc, _type) \
|
2006-02-10 18:00:36 +03:00
|
|
|
NS_LogRelease((_p), (_rc), (_type))
|
2003-08-05 09:29:10 +04:00
|
|
|
|
|
|
|
#define MOZ_COUNT_CTOR(_type) \
|
2012-10-02 12:24:12 +04:00
|
|
|
do { \
|
2006-02-10 18:00:36 +03:00
|
|
|
NS_LogCtor((void*)this, #_type, sizeof(*this)); \
|
2012-10-02 12:24:12 +04:00
|
|
|
} while (0)
|
2003-08-05 09:29:10 +04:00
|
|
|
|
2010-12-02 19:15:48 +03:00
|
|
|
#define MOZ_COUNT_CTOR_INHERITED(_type, _base) \
|
2012-10-02 12:24:12 +04:00
|
|
|
do { \
|
2010-12-02 19:15:48 +03:00
|
|
|
NS_LogCtor((void*)this, #_type, sizeof(*this) - sizeof(_base)); \
|
2012-10-02 12:24:12 +04:00
|
|
|
} while (0)
|
2010-12-02 19:15:48 +03:00
|
|
|
|
2003-08-05 09:29:10 +04:00
|
|
|
#define MOZ_COUNT_DTOR(_type) \
|
2012-10-02 12:24:12 +04:00
|
|
|
do { \
|
2006-02-10 18:00:36 +03:00
|
|
|
NS_LogDtor((void*)this, #_type, sizeof(*this)); \
|
2012-10-02 12:24:12 +04:00
|
|
|
} while (0)
|
2003-08-05 09:29:10 +04:00
|
|
|
|
2010-12-02 19:15:48 +03:00
|
|
|
#define MOZ_COUNT_DTOR_INHERITED(_type, _base) \
|
2012-10-02 12:24:12 +04:00
|
|
|
do { \
|
2010-12-02 19:15:48 +03:00
|
|
|
NS_LogDtor((void*)this, #_type, sizeof(*this) - sizeof(_base)); \
|
2012-10-02 12:24:12 +04:00
|
|
|
} while (0)
|
2010-12-02 19:15:48 +03:00
|
|
|
|
2006-02-15 23:23:08 +03:00
|
|
|
/* nsCOMPtr.h allows these macros to be defined by clients
|
|
|
|
* These logging functions require dynamic_cast<void*>, so they don't
|
|
|
|
* do anything useful if we don't have dynamic_cast<void*>. */
|
2003-08-05 09:29:10 +04:00
|
|
|
#define NSCAP_LOG_ASSIGNMENT(_c, _p) \
|
|
|
|
if (_p) \
|
2007-07-08 11:08:04 +04:00
|
|
|
NS_LogCOMPtrAddRef((_c),static_cast<nsISupports*>(_p))
|
2003-08-05 09:29:10 +04:00
|
|
|
|
|
|
|
#define NSCAP_LOG_RELEASE(_c, _p) \
|
|
|
|
if (_p) \
|
2007-07-08 11:08:04 +04:00
|
|
|
NS_LogCOMPtrRelease((_c), static_cast<nsISupports*>(_p))
|
2003-08-05 09:29:10 +04:00
|
|
|
|
|
|
|
#else /* !NS_BUILD_REFCNT_LOGGING */
|
|
|
|
|
|
|
|
#define NS_LOG_ADDREF(_p, _rc, _type, _size)
|
|
|
|
#define NS_LOG_RELEASE(_p, _rc, _type)
|
|
|
|
#define MOZ_COUNT_CTOR(_type)
|
2010-12-02 19:15:48 +03:00
|
|
|
#define MOZ_COUNT_CTOR_INHERITED(_type, _base)
|
2003-08-05 09:29:10 +04:00
|
|
|
#define MOZ_COUNT_DTOR(_type)
|
2010-12-02 19:15:48 +03:00
|
|
|
#define MOZ_COUNT_DTOR_INHERITED(_type, _base)
|
2003-08-05 09:29:10 +04:00
|
|
|
|
|
|
|
#endif /* NS_BUILD_REFCNT_LOGGING */
|
|
|
|
|
2006-02-15 23:23:08 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
2003-08-05 09:29:10 +04:00
|
|
|
class nsTraceRefcnt {
|
|
|
|
public:
|
2006-02-10 18:00:36 +03:00
|
|
|
inline static void LogAddRef(void* aPtr, nsrefcnt aNewRefCnt,
|
2012-08-22 19:56:38 +04:00
|
|
|
const char* aTypeName, uint32_t aInstanceSize) {
|
2006-02-10 18:00:36 +03:00
|
|
|
NS_LogAddRef(aPtr, aNewRefCnt, aTypeName, aInstanceSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static void LogRelease(void* aPtr, nsrefcnt aNewRefCnt,
|
|
|
|
const char* aTypeName) {
|
|
|
|
NS_LogRelease(aPtr, aNewRefCnt, aTypeName);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static void LogCtor(void* aPtr, const char* aTypeName,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aInstanceSize) {
|
2006-02-10 18:00:36 +03:00
|
|
|
NS_LogCtor(aPtr, aTypeName, aInstanceSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static void LogDtor(void* aPtr, const char* aTypeName,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aInstanceSize) {
|
2006-02-10 18:00:36 +03:00
|
|
|
NS_LogDtor(aPtr, aTypeName, aInstanceSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static void LogAddCOMPtr(void *aCOMPtr, nsISupports *aObject) {
|
|
|
|
NS_LogCOMPtrAddRef(aCOMPtr, aObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static void LogReleaseCOMPtr(void *aCOMPtr, nsISupports *aObject) {
|
|
|
|
NS_LogCOMPtrRelease(aCOMPtr, aObject);
|
|
|
|
}
|
2003-08-05 09:29:10 +04:00
|
|
|
};
|
2006-02-10 18:00:36 +03:00
|
|
|
|
2006-02-15 23:23:08 +03:00
|
|
|
#endif /* defined(__cplusplus) */
|
|
|
|
|
2003-08-05 09:29:10 +04:00
|
|
|
#endif /* nsTraceRefcnt_h___ */
|