PageRenderTime 31ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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. #include "nsXPCOM.h"
  41. /* By default refcnt logging is not part of the build. */
  42. #undef NS_BUILD_REFCNT_LOGGING
  43. #if (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
  44. /* Make refcnt logging part of the build. This doesn't mean that
  45. * actual logging will occur (that requires a separate enable; see
  46. * nsTraceRefcnt.h for more information). */
  47. #define NS_BUILD_REFCNT_LOGGING 1
  48. #endif
  49. /* If NO_BUILD_REFCNT_LOGGING is defined then disable refcnt logging
  50. * in the build. This overrides FORCE_BUILD_REFCNT_LOGGING. */
  51. #if defined(NO_BUILD_REFCNT_LOGGING)
  52. #undef NS_BUILD_REFCNT_LOGGING
  53. #endif
  54. #ifdef NS_BUILD_REFCNT_LOGGING
  55. #define NS_LOG_ADDREF(_p, _rc, _type, _size) \
  56. NS_LogAddRef((_p), (_rc), (_type), (PRUint32) (_size))
  57. #define NS_LOG_RELEASE(_p, _rc, _type) \
  58. NS_LogRelease((_p), (_rc), (_type))
  59. #define MOZ_DECL_CTOR_COUNTER(_type)
  60. #define MOZ_COUNT_CTOR(_type) \
  61. PR_BEGIN_MACRO \
  62. NS_LogCtor((void*)this, #_type, sizeof(*this)); \
  63. PR_END_MACRO
  64. #define MOZ_COUNT_DTOR(_type) \
  65. PR_BEGIN_MACRO \
  66. NS_LogDtor((void*)this, #_type, sizeof(*this)); \
  67. PR_END_MACRO
  68. /* nsCOMPtr.h allows these macros to be defined by clients
  69. * These logging functions require dynamic_cast<void*>, so they don't
  70. * do anything useful if we don't have dynamic_cast<void*>. */
  71. #define NSCAP_LOG_ASSIGNMENT(_c, _p) \
  72. if (_p) \
  73. NS_LogCOMPtrAddRef((_c),static_cast<nsISupports*>(_p))
  74. #define NSCAP_LOG_RELEASE(_c, _p) \
  75. if (_p) \
  76. NS_LogCOMPtrRelease((_c), static_cast<nsISupports*>(_p))
  77. #else /* !NS_BUILD_REFCNT_LOGGING */
  78. #define NS_LOG_ADDREF(_p, _rc, _type, _size)
  79. #define NS_LOG_RELEASE(_p, _rc, _type)
  80. #define MOZ_DECL_CTOR_COUNTER(_type)
  81. #define MOZ_COUNT_CTOR(_type)
  82. #define MOZ_COUNT_DTOR(_type)
  83. #endif /* NS_BUILD_REFCNT_LOGGING */
  84. #ifdef __cplusplus
  85. class nsTraceRefcnt {
  86. public:
  87. inline static void LogAddRef(void* aPtr, nsrefcnt aNewRefCnt,
  88. const char* aTypeName, PRUint32 aInstanceSize) {
  89. NS_LogAddRef(aPtr, aNewRefCnt, aTypeName, aInstanceSize);
  90. }
  91. inline static void LogRelease(void* aPtr, nsrefcnt aNewRefCnt,
  92. const char* aTypeName) {
  93. NS_LogRelease(aPtr, aNewRefCnt, aTypeName);
  94. }
  95. inline static void LogCtor(void* aPtr, const char* aTypeName,
  96. PRUint32 aInstanceSize) {
  97. NS_LogCtor(aPtr, aTypeName, aInstanceSize);
  98. }
  99. inline static void LogDtor(void* aPtr, const char* aTypeName,
  100. PRUint32 aInstanceSize) {
  101. NS_LogDtor(aPtr, aTypeName, aInstanceSize);
  102. }
  103. inline static void LogAddCOMPtr(void *aCOMPtr, nsISupports *aObject) {
  104. NS_LogCOMPtrAddRef(aCOMPtr, aObject);
  105. }
  106. inline static void LogReleaseCOMPtr(void *aCOMPtr, nsISupports *aObject) {
  107. NS_LogCOMPtrRelease(aCOMPtr, aObject);
  108. }
  109. };
  110. #endif /* defined(__cplusplus) */
  111. #endif /* nsTraceRefcnt_h___ */