VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/base/nsGarbageCollector.c@ 65406

Last change on this file since 65406 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 *
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * The Original Code is the Mozilla browser.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications, Inc.
20 * Portions created by the Initial Developer are Copyright (C) 1999
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 * Patrick Beard <[email protected]>
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40/*
41 nsGarbageCollector.c
42 */
43
44#ifdef GC_LEAK_DETECTOR
45
46/* for FILE */
47#include <stdio.h>
48
49/* NSPR stuff */
50#include "generic_threads.h"
51#include "prthread.h"
52#include "prlock.h"
53
54/* Linux/Win32 export private NSPR files to include/private */
55#ifdef XP_MAC
56#include "pprthred.h"
57#else
58#include "private/pprthred.h"
59#endif
60
61#include "nsLeakDetector.h"
62
63extern FILE *GC_stdout, *GC_stderr;
64
65extern void GC_gcollect(void);
66extern void GC_clear_roots(void);
67
68static PRStatus PR_CALLBACK scanner(PRThread* t, void** baseAddr, PRUword count, void* closure)
69{
70 char* begin = (char*)baseAddr;
71 char* end = (char*)(baseAddr + count);
72 GC_mark_range_proc marker = (GC_mark_range_proc) closure;
73 marker(begin, end);
74 return PR_SUCCESS;
75}
76
77static void mark_all_stacks(GC_mark_range_proc marker)
78{
79 /* PR_ThreadScanStackPointers(PR_GetCurrentThread(), &scanner, marker); */
80 PR_ScanStackPointers(&scanner, (void *)marker);
81}
82
83static void locker(void* mutex)
84{
85 PR_Lock(mutex);
86}
87
88static void unlocker(void* mutex)
89{
90 PR_Unlock(mutex);
91}
92
93static void stopper(void* unused)
94{
95 PR_SuspendAll();
96}
97
98static void starter(void* unused)
99{
100 PR_ResumeAll();
101}
102
103nsresult NS_InitGarbageCollector()
104{
105 PRLock* mutex;
106
107 /* redirect GC's stderr to catch startup leaks. */
108 GC_stderr = fopen("StartupLeaks", "w");
109
110 mutex = PR_NewLock();
111 if (mutex == NULL)
112 return NS_ERROR_FAILURE;
113
114 GC_generic_init_threads(&mark_all_stacks, mutex,
115 &locker, &unlocker,
116 &stopper, &starter);
117
118 return NS_OK;
119}
120
121nsresult NS_ShutdownGarbageCollector()
122{
123 /* do anything you need to shut down the collector. */
124 return NS_OK;
125}
126
127#endif /* GC_LEAK_DETECTOR */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette