PageRenderTime 83ms CodeModel.GetById 41ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 0ms

/gecko_api/include/nsTraceRefcnt.h

http://firefox-mac-pdf.googlecode.com/
C++ Header | 135 lines | 65 code | 24 blank | 46 comment | 3 complexity | c6c5d18f20719838f4df85f9344adc08 MD5 | raw file
  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 "nsXPCOM.h"
 42
 43/* By default refcnt logging is not part of the build. */
 44#undef NS_BUILD_REFCNT_LOGGING
 45
 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
 52
 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
 58
 59#ifdef NS_BUILD_REFCNT_LOGGING
 60
 61#define NS_LOG_ADDREF(_p, _rc, _type, _size) \
 62  NS_LogAddRef((_p), (_rc), (_type), (PRUint32) (_size))
 63
 64#define NS_LOG_RELEASE(_p, _rc, _type) \
 65  NS_LogRelease((_p), (_rc), (_type))
 66
 67#define MOZ_DECL_CTOR_COUNTER(_type)
 68
 69#define MOZ_COUNT_CTOR(_type)                                 \
 70PR_BEGIN_MACRO                                                \
 71  NS_LogCtor((void*)this, #_type, sizeof(*this));             \
 72PR_END_MACRO
 73
 74#define MOZ_COUNT_DTOR(_type)                                 \
 75PR_BEGIN_MACRO                                                \
 76  NS_LogDtor((void*)this, #_type, sizeof(*this));             \
 77PR_END_MACRO
 78
 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))
 85
 86#define NSCAP_LOG_RELEASE(_c, _p)                                   \
 87  if (_p)                                                           \
 88    NS_LogCOMPtrRelease((_c), static_cast<nsISupports*>(_p))
 89
 90#else /* !NS_BUILD_REFCNT_LOGGING */
 91
 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)
 97
 98#endif /* NS_BUILD_REFCNT_LOGGING */
 99
100#ifdef __cplusplus
101
102class nsTraceRefcnt {
103public:
104  inline static void LogAddRef(void* aPtr, nsrefcnt aNewRefCnt,
105                               const char* aTypeName, PRUint32 aInstanceSize) {
106    NS_LogAddRef(aPtr, aNewRefCnt, aTypeName, aInstanceSize);
107  }
108
109  inline static void LogRelease(void* aPtr, nsrefcnt aNewRefCnt,
110                                const char* aTypeName) {
111    NS_LogRelease(aPtr, aNewRefCnt, aTypeName);
112  }
113
114  inline static void LogCtor(void* aPtr, const char* aTypeName,
115                             PRUint32 aInstanceSize) {
116    NS_LogCtor(aPtr, aTypeName, aInstanceSize);
117  }
118
119  inline static void LogDtor(void* aPtr, const char* aTypeName,
120                             PRUint32 aInstanceSize) {
121    NS_LogDtor(aPtr, aTypeName, aInstanceSize);
122  }
123
124  inline static void LogAddCOMPtr(void *aCOMPtr, nsISupports *aObject) {
125    NS_LogCOMPtrAddRef(aCOMPtr, aObject);
126  }
127
128  inline static void LogReleaseCOMPtr(void *aCOMPtr, nsISupports *aObject) {
129    NS_LogCOMPtrRelease(aCOMPtr, aObject);
130  }
131};
132
133#endif /* defined(__cplusplus) */
134
135#endif /* nsTraceRefcnt_h___ */