Fixes XPCOM glue leaving behind exit routine after DLL is unloaded. r=adamlock sr=darin, a=asa, b=184548

This commit is contained in:
dougt%netscape.com 2002-12-10 01:37:56 +00:00
Родитель 75d8ea438b
Коммит 013696fd5e
2 изменённых файлов: 24 добавлений и 53 удалений

Просмотреть файл

@ -39,8 +39,6 @@
#include "nsMemory.h"
#include "nsXPCOMPrivate.h"
static nsIMemory* gMemory = nsnull;
static NS_METHOD FreeGlobalMemory(void)
@ -62,6 +60,20 @@ SetupGlobalMemory()
return gMemory;
}
#ifdef XPCOM_GLUE
nsresult GlueStartupMemory()
{
NS_ASSERTION(!gMemory, "bad call");
NS_GetMemoryManager(&gMemory);
NS_ASSERTION(gMemory, "can't get memory manager!");
return NS_OK;
}
void GlueShutdownMemory()
{
NS_IF_RELEASE(gMemory);
}
#endif
////////////////////////////////////////////////////////////////////////////////
// nsMemory static helper routines

Просмотреть файл

@ -47,10 +47,7 @@
static PRLibrary *xpcomLib = nsnull;
static XPCOMFunctions *xpcomFunctions = nsnull;
#ifdef DEBUG_dougt
#define XPCOM_GLUE_FLUSH_HEAP
#endif
static nsIMemory* xpcomMemory = nsnull;
//#define XPCOM_GLUE_NO_DYNAMIC_LOADING
@ -65,6 +62,11 @@ static XPCOMFunctions *xpcomFunctions = nsnull;
#endif
#endif
extern nsresult GlueStartupMemory();
extern void GlueShutdownMemory();
extern "C"
nsresult NS_COM XPCOMGlueStartup(const char* xpcomFile)
{
@ -109,51 +111,11 @@ nsresult NS_COM XPCOMGlueStartup(const char* xpcomFile)
xpcomLib = nsnull;
return NS_ERROR_FAILURE;
}
return NS_OK;
#endif
}
#ifdef XPCOM_GLUE_FLUSH_HEAP
static void FlushHeap()
{
#if defined(XP_WIN32)
// Heap compaction and shrink working set now
#ifdef DEBUG_dougt
PRIntervalTime start = PR_IntervalNow();
int ret =
// startup the nsMemory
return GlueStartupMemory();
#endif
_heapmin();
#ifdef DEBUG_dougt
printf("DEBUG: HeapCompact() %s - %d ms\n", (!ret ? "success" : "FAILED"),
PR_IntervalToMilliseconds(PR_IntervalNow()-start));
#endif
// shrink working set if we can
// This function call is available only on winnt and above.
typedef BOOL WINAPI SetProcessWorkingSetProc(HANDLE hProcess, SIZE_T dwMinimumWorkingSetSize,
SIZE_T dwMaximumWorkingSetSize);
SetProcessWorkingSetProc *setProcessWorkingSetSizeP = NULL;
HMODULE kernel = GetModuleHandle("kernel32.dll");
if (kernel) {
setProcessWorkingSetSizeP = (SetProcessWorkingSetProc *)
GetProcAddress(kernel, "SetProcessWorkingSetSize");
}
if (setProcessWorkingSetSizeP) {
// shrink working set
#ifdef DEBUG_dougt
start = PR_IntervalNow();
#endif
(*setProcessWorkingSetSizeP)(GetCurrentProcess(), -1, -1);
#ifdef DEBUG_dougt
printf("DEBUG: Honey! I shrunk the resident-set! - %d ms\n",
PR_IntervalToMilliseconds(PR_IntervalNow() - start));
#endif
}
#endif
}
#endif
extern "C"
nsresult NS_COM XPCOMGlueShutdown()
@ -170,11 +132,8 @@ nsresult NS_COM XPCOMGlueShutdown()
PR_UnloadLibrary(xpcomLib);
xpcomLib = nsnull;
}
#ifdef XPCOM_GLUE_FLUSH_HEAP
// should the application do this instead of us?
FlushHeap();
#endif
GlueShutdownMemory();
return NS_OK;
#endif
}