PageRenderTime 158ms CodeModel.GetById 81ms app.highlight 17ms RepoModel.GetById 53ms app.codeStats 1ms

/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
38#ifndef nsCycleCollector_h__
39#define nsCycleCollector_h__
40
41// NOTE: If you use header files to define DEBUG_CC, you must do so here
42// *and* in nsCycleCollectionParticipant.h
43//#define DEBUG_CC
44
45class nsISupports;
46class nsCycleCollectionParticipant;
47class nsCycleCollectionTraversalCallback;
48
49// An nsCycleCollectionLanguageRuntime is a per-language object that
50// implements language-specific aspects of the cycle collection task.
51
52struct nsCycleCollectionLanguageRuntime
53{
54    virtual nsresult BeginCycleCollection(nsCycleCollectionTraversalCallback &cb) = 0;
55    virtual nsresult FinishCycleCollection() = 0;
56    virtual nsCycleCollectionParticipant *ToParticipant(void *p) = 0;
57#ifdef DEBUG_CC
58    virtual void PrintAllReferencesTo(void *p) = 0;
59#endif
60};
61
62nsresult nsCycleCollector_startup();
63// Returns the number of collected nodes.
64NS_COM PRUint32 nsCycleCollector_collect();
65NS_COM PRUint32 nsCycleCollector_suspectedCount();
66void nsCycleCollector_shutdown();
67
68// The JS runtime is special, it needs to call cycle collection during its GC.
69// If the JS runtime is registered nsCycleCollector_collect will call
70// nsCycleCollectionJSRuntime::Collect which will call
71// nsCycleCollector_doCollect, else nsCycleCollector_collect will call
72// nsCycleCollector_doCollect directly.
73struct nsCycleCollectionJSRuntime : public nsCycleCollectionLanguageRuntime
74{
75    /**
76     * Runs cycle collection and returns whether cycle collection collected
77     * anything.
78     */
79    virtual PRBool Collect() = 0;
80};
81// Returns PR_TRUE if cycle collection was started.
82NS_COM PRBool nsCycleCollector_beginCollection();
83// Returns PR_TRUE if some nodes were collected. Should only be called after
84// nsCycleCollector_beginCollection() returned PR_TRUE.
85NS_COM PRBool nsCycleCollector_finishCollection();
86
87#ifdef DEBUG
88NS_COM void nsCycleCollector_DEBUG_shouldBeFreed(nsISupports *n);
89NS_COM void nsCycleCollector_DEBUG_wasFreed(nsISupports *n);
90#endif
91
92// Helpers for interacting with language-identified scripts
93
94NS_COM void nsCycleCollector_registerRuntime(PRUint32 langID, nsCycleCollectionLanguageRuntime *rt);
95NS_COM void nsCycleCollector_forgetRuntime(PRUint32 langID);
96
97#endif // nsCycleCollector_h__