On x86 compilers without fastcall, simulate it when invoking traces and un-simulate...
[wine-gecko.git] / xpcom / glue / nsTraceRefcnt.h
blob9d37e9c8900f858e277e734a07f9803f12f4f19f
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla Communicator client code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * L. David Baron <dbaron@dbaron.org>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsTraceRefcnt_h___
39 #define nsTraceRefcnt_h___
41 #include "nsXPCOM.h"
43 /* By default refcnt logging is not part of the build. */
44 #undef NS_BUILD_REFCNT_LOGGING
46 #if (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
47 /* Make refcnt logging part of the build. This doesn't mean that
48 * actual logging will occur (that requires a separate enable; see
49 * nsTraceRefcnt.h for more information). */
50 #define NS_BUILD_REFCNT_LOGGING 1
51 #endif
53 /* If NO_BUILD_REFCNT_LOGGING is defined then disable refcnt logging
54 * in the build. This overrides FORCE_BUILD_REFCNT_LOGGING. */
55 #if defined(NO_BUILD_REFCNT_LOGGING)
56 #undef NS_BUILD_REFCNT_LOGGING
57 #endif
59 #ifdef NS_BUILD_REFCNT_LOGGING
61 #define NS_LOG_ADDREF(_p, _rc, _type, _size) \
62 NS_LogAddRef((_p), (_rc), (_type), (PRUint32) (_size))
64 #define NS_LOG_RELEASE(_p, _rc, _type) \
65 NS_LogRelease((_p), (_rc), (_type))
67 #define MOZ_DECL_CTOR_COUNTER(_type)
69 #define MOZ_COUNT_CTOR(_type) \
70 PR_BEGIN_MACRO \
71 NS_LogCtor((void*)this, #_type, sizeof(*this)); \
72 PR_END_MACRO
74 #define MOZ_COUNT_DTOR(_type) \
75 PR_BEGIN_MACRO \
76 NS_LogDtor((void*)this, #_type, sizeof(*this)); \
77 PR_END_MACRO
79 /* nsCOMPtr.h allows these macros to be defined by clients
80 * These logging functions require dynamic_cast<void*>, so they don't
81 * do anything useful if we don't have dynamic_cast<void*>. */
82 #define NSCAP_LOG_ASSIGNMENT(_c, _p) \
83 if (_p) \
84 NS_LogCOMPtrAddRef((_c),static_cast<nsISupports*>(_p))
86 #define NSCAP_LOG_RELEASE(_c, _p) \
87 if (_p) \
88 NS_LogCOMPtrRelease((_c), static_cast<nsISupports*>(_p))
90 #else /* !NS_BUILD_REFCNT_LOGGING */
92 #define NS_LOG_ADDREF(_p, _rc, _type, _size)
93 #define NS_LOG_RELEASE(_p, _rc, _type)
94 #define MOZ_DECL_CTOR_COUNTER(_type)
95 #define MOZ_COUNT_CTOR(_type)
96 #define MOZ_COUNT_DTOR(_type)
98 #endif /* NS_BUILD_REFCNT_LOGGING */
100 #ifdef __cplusplus
102 class nsTraceRefcnt {
103 public:
104 inline static void LogAddRef(void* aPtr, nsrefcnt aNewRefCnt,
105 const char* aTypeName, PRUint32 aInstanceSize) {
106 NS_LogAddRef(aPtr, aNewRefCnt, aTypeName, aInstanceSize);
109 inline static void LogRelease(void* aPtr, nsrefcnt aNewRefCnt,
110 const char* aTypeName) {
111 NS_LogRelease(aPtr, aNewRefCnt, aTypeName);
114 inline static void LogCtor(void* aPtr, const char* aTypeName,
115 PRUint32 aInstanceSize) {
116 NS_LogCtor(aPtr, aTypeName, aInstanceSize);
119 inline static void LogDtor(void* aPtr, const char* aTypeName,
120 PRUint32 aInstanceSize) {
121 NS_LogDtor(aPtr, aTypeName, aInstanceSize);
124 inline static void LogAddCOMPtr(void *aCOMPtr, nsISupports *aObject) {
125 NS_LogCOMPtrAddRef(aCOMPtr, aObject);
128 inline static void LogReleaseCOMPtr(void *aCOMPtr, nsISupports *aObject) {
129 NS_LogCOMPtrRelease(aCOMPtr, aObject);
133 #endif /* defined(__cplusplus) */
135 #endif /* nsTraceRefcnt_h___ */