VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/base/nsMemoryImpl.cpp@ 101848

最後變更 在這個檔案從101848是 101848,由 vboxsync 提交於 17 月 前

libs/xpcom: Get rid of the memory flusher functionality which is not enabled in our builds, bugref:10545

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 3.9 KB
 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 * 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 *
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#include "nsMemoryImpl.h"
39#include "prmem.h"
40#include "nsAlgorithm.h"
41#include "nsIServiceManager.h"
42#include "nsIObserverService.h"
43#include "nsAutoLock.h"
44#include "nsIEventQueueService.h"
45#include "nsString.h"
46
47nsMemoryImpl* gMemory = nsnull;
48
49NS_IMPL_THREADSAFE_ISUPPORTS1(nsMemoryImpl, nsIMemory)
50
51NS_METHOD
52nsMemoryImpl::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
53{
54 NS_ENSURE_ARG_POINTER(aInstancePtr);
55 NS_ENSURE_PROPER_AGGREGATION(outer, aIID);
56 if (gMemory && NS_SUCCEEDED(gMemory->QueryInterface(aIID, aInstancePtr)))
57 return NS_OK;
58
59 nsMemoryImpl* mm = new nsMemoryImpl();
60 if (mm == NULL)
61 return NS_ERROR_OUT_OF_MEMORY;
62
63 nsresult rv;
64
65 do {
66 rv = mm->QueryInterface(aIID, aInstancePtr);
67 if (NS_FAILED(rv))
68 break;
69
70 rv = NS_OK;
71 } while (0);
72
73 if (NS_FAILED(rv))
74 delete mm;
75
76 return rv;
77}
78
79
80nsMemoryImpl::nsMemoryImpl()
81{
82}
83
84nsMemoryImpl::~nsMemoryImpl()
85{
86}
87
88////////////////////////////////////////////////////////////////////////////////
89
90NS_IMETHODIMP_(void *)
91nsMemoryImpl::Alloc(PRSize size)
92{
93 NS_ASSERTION(size, "nsMemoryImpl::Alloc of 0");
94 void* result = PR_Malloc(size);
95 return result;
96}
97
98NS_IMETHODIMP_(void *)
99nsMemoryImpl::Realloc(void * ptr, PRSize size)
100{
101 void* result = PR_Realloc(ptr, size);
102 return result;
103}
104
105NS_IMETHODIMP_(void)
106nsMemoryImpl::Free(void * ptr)
107{
108 PR_Free(ptr);
109}
110
111NS_IMETHODIMP
112nsMemoryImpl::HeapMinimize(PRBool aImmediate)
113{
114 return NS_OK;
115}
116
117NS_IMETHODIMP
118nsMemoryImpl::IsLowMemory(PRBool *result)
119{
120 *result = PR_FALSE;
121 return NS_OK;
122}
123
124static void
125EnsureGlobalMemoryService()
126{
127 if (gMemory) return;
128 nsresult rv = nsMemoryImpl::Create(nsnull, NS_GET_IID(nsIMemory), (void**)&gMemory);
129 NS_ASSERTION(NS_SUCCEEDED(rv), "nsMemoryImpl::Create failed");
130 NS_ASSERTION(gMemory, "improper xpcom initialization");
131}
132
133nsresult
134nsMemoryImpl::Startup()
135{
136 EnsureGlobalMemoryService();
137 if (! gMemory)
138 return NS_ERROR_FAILURE;
139
140 return NS_OK;
141}
142
143nsresult
144nsMemoryImpl::Shutdown()
145{
146 if (gMemory) {
147 NS_RELEASE(gMemory);
148 gMemory = nsnull;
149 }
150
151 return NS_OK;
152}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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