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
|
---|
4 | *
|
---|
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/
|
---|
9 | *
|
---|
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.
|
---|
14 | *
|
---|
15 | * The Original Code is Mozilla Communicator client code.
|
---|
16 | *
|
---|
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.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | * L. David Baron <dbaron@dbaron.org>
|
---|
24 | *
|
---|
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.
|
---|
36 | *
|
---|
37 | * ***** END LICENSE BLOCK ***** */
|
---|
38 | #ifndef nsTraceRefcnt_h___
|
---|
39 | #define nsTraceRefcnt_h___
|
---|
40 |
|
---|
41 | #include "nscore.h"
|
---|
42 |
|
---|
43 | class nsISupports;
|
---|
44 |
|
---|
45 | // By default refcnt logging is not part of the build.
|
---|
46 | #undef NS_BUILD_REFCNT_LOGGING
|
---|
47 |
|
---|
48 | #if (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
|
---|
49 | // Make refcnt logging part of the build. This doesn't mean that
|
---|
50 | // actual logging will occur (that requires a separate enable; see
|
---|
51 | // nsTraceRefcnt.h for more information).
|
---|
52 | #define NS_BUILD_REFCNT_LOGGING 1
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | // If NO_BUILD_REFCNT_LOGGING is defined then disable refcnt logging
|
---|
56 | // in the build. This overrides FORCE_BUILD_REFCNT_LOGGING.
|
---|
57 | #if defined(NO_BUILD_REFCNT_LOGGING)
|
---|
58 | #undef NS_BUILD_REFCNT_LOGGING
|
---|
59 | #endif
|
---|
60 |
|
---|
61 | #ifdef NS_BUILD_REFCNT_LOGGING
|
---|
62 |
|
---|
63 | #define NS_LOG_ADDREF(_p, _rc, _type, _size) \
|
---|
64 | nsTraceRefcnt::LogAddRef((_p), (_rc), (_type), (PRUint32) (_size))
|
---|
65 |
|
---|
66 | #define NS_LOG_RELEASE(_p, _rc, _type) \
|
---|
67 | nsTraceRefcnt::LogRelease((_p), (_rc), (_type))
|
---|
68 |
|
---|
69 | #define MOZ_DECL_CTOR_COUNTER(_type)
|
---|
70 |
|
---|
71 | #define MOZ_COUNT_CTOR(_type) \
|
---|
72 | PR_BEGIN_MACRO \
|
---|
73 | nsTraceRefcnt::LogCtor((void*)this, #_type, sizeof(*this)); \
|
---|
74 | PR_END_MACRO
|
---|
75 |
|
---|
76 | #define MOZ_COUNT_DTOR(_type) \
|
---|
77 | PR_BEGIN_MACRO \
|
---|
78 | nsTraceRefcnt::LogDtor((void*)this, #_type, sizeof(*this)); \
|
---|
79 | PR_END_MACRO
|
---|
80 |
|
---|
81 | #ifdef HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR // from autoconf (XXX needs to be
|
---|
82 | // set for non-autoconf platforms)
|
---|
83 |
|
---|
84 | // nsCOMPtr.h allows these macros to be defined by clients
|
---|
85 | // These logging functions require dynamic_cast<void *>, so we don't
|
---|
86 | // define these macros if we don't have dynamic_cast.
|
---|
87 | #define NSCAP_LOG_ASSIGNMENT(_c, _p) \
|
---|
88 | if (_p) \
|
---|
89 | nsTraceRefcnt::LogAddCOMPtr((_c),NS_STATIC_CAST(nsISupports*,_p))
|
---|
90 |
|
---|
91 | #define NSCAP_LOG_RELEASE(_c, _p) \
|
---|
92 | if (_p) \
|
---|
93 | nsTraceRefcnt::LogReleaseCOMPtr((_c), NS_STATIC_CAST(nsISupports*,_p))
|
---|
94 |
|
---|
95 | #endif /* HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR */
|
---|
96 |
|
---|
97 | #else /* !NS_BUILD_REFCNT_LOGGING */
|
---|
98 |
|
---|
99 | #define NS_LOG_ADDREF(_p, _rc, _type, _size)
|
---|
100 | #define NS_LOG_RELEASE(_p, _rc, _type)
|
---|
101 | #define MOZ_DECL_CTOR_COUNTER(_type)
|
---|
102 | #define MOZ_COUNT_CTOR(_type)
|
---|
103 | #define MOZ_COUNT_DTOR(_type)
|
---|
104 |
|
---|
105 | #endif /* NS_BUILD_REFCNT_LOGGING */
|
---|
106 |
|
---|
107 | //----------------------------------------------------------------------
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Note: The implementations for these methods are no-ops in a build
|
---|
111 | * where NS_BUILD_REFCNT_LOGGING is disabled.
|
---|
112 | */
|
---|
113 | class nsTraceRefcnt {
|
---|
114 | public:
|
---|
115 | static NS_COM void LogAddRef(void* aPtr,
|
---|
116 | nsrefcnt aNewRefCnt,
|
---|
117 | const char* aTypeName,
|
---|
118 | PRUint32 aInstanceSize);
|
---|
119 |
|
---|
120 | static NS_COM void LogRelease(void* aPtr,
|
---|
121 | nsrefcnt aNewRefCnt,
|
---|
122 | const char* aTypeName);
|
---|
123 |
|
---|
124 | static NS_COM void LogCtor(void* aPtr, const char* aTypeName,
|
---|
125 | PRUint32 aInstanceSize);
|
---|
126 |
|
---|
127 | static NS_COM void LogDtor(void* aPtr, const char* aTypeName,
|
---|
128 | PRUint32 aInstanceSize);
|
---|
129 |
|
---|
130 | static NS_COM void LogAddCOMPtr(void *aCOMPtr, nsISupports *aObject);
|
---|
131 |
|
---|
132 | static NS_COM void LogReleaseCOMPtr(void *aCOMPtr, nsISupports *aObject);
|
---|
133 |
|
---|
134 | };
|
---|
135 | #endif /* nsTraceRefcnt_h___ */
|
---|