PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/gecko_api/include/nsCycleCollector.h

http://firefox-mac-pdf.googlecode.com/
C Header | 97 lines | 31 code | 11 blank | 55 comment | 0 complexity | 0ce7d785dabef658ee53f86fb492d44b 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.org code.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * The Mozilla Foundation.
  19. * Portions created by the Initial Developer are Copyright (C) 2006
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either of the GNU General Public License Version 2 or later (the "GPL"),
  26. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. #ifndef nsCycleCollector_h__
  38. #define nsCycleCollector_h__
  39. // NOTE: If you use header files to define DEBUG_CC, you must do so here
  40. // *and* in nsCycleCollectionParticipant.h
  41. //#define DEBUG_CC
  42. class nsISupports;
  43. class nsCycleCollectionParticipant;
  44. class nsCycleCollectionTraversalCallback;
  45. // An nsCycleCollectionLanguageRuntime is a per-language object that
  46. // implements language-specific aspects of the cycle collection task.
  47. struct nsCycleCollectionLanguageRuntime
  48. {
  49. virtual nsresult BeginCycleCollection(nsCycleCollectionTraversalCallback &cb) = 0;
  50. virtual nsresult FinishCycleCollection() = 0;
  51. virtual nsCycleCollectionParticipant *ToParticipant(void *p) = 0;
  52. #ifdef DEBUG_CC
  53. virtual void PrintAllReferencesTo(void *p) = 0;
  54. #endif
  55. };
  56. nsresult nsCycleCollector_startup();
  57. // Returns the number of collected nodes.
  58. NS_COM PRUint32 nsCycleCollector_collect();
  59. NS_COM PRUint32 nsCycleCollector_suspectedCount();
  60. void nsCycleCollector_shutdown();
  61. // The JS runtime is special, it needs to call cycle collection during its GC.
  62. // If the JS runtime is registered nsCycleCollector_collect will call
  63. // nsCycleCollectionJSRuntime::Collect which will call
  64. // nsCycleCollector_doCollect, else nsCycleCollector_collect will call
  65. // nsCycleCollector_doCollect directly.
  66. struct nsCycleCollectionJSRuntime : public nsCycleCollectionLanguageRuntime
  67. {
  68. /**
  69. * Runs cycle collection and returns whether cycle collection collected
  70. * anything.
  71. */
  72. virtual PRBool Collect() = 0;
  73. };
  74. // Returns PR_TRUE if cycle collection was started.
  75. NS_COM PRBool nsCycleCollector_beginCollection();
  76. // Returns PR_TRUE if some nodes were collected. Should only be called after
  77. // nsCycleCollector_beginCollection() returned PR_TRUE.
  78. NS_COM PRBool nsCycleCollector_finishCollection();
  79. #ifdef DEBUG
  80. NS_COM void nsCycleCollector_DEBUG_shouldBeFreed(nsISupports *n);
  81. NS_COM void nsCycleCollector_DEBUG_wasFreed(nsISupports *n);
  82. #endif
  83. // Helpers for interacting with language-identified scripts
  84. NS_COM void nsCycleCollector_registerRuntime(PRUint32 langID, nsCycleCollectionLanguageRuntime *rt);
  85. NS_COM void nsCycleCollector_forgetRuntime(PRUint32 langID);
  86. #endif // nsCycleCollector_h__