/* * private static void UnloadAppDomain(Object appDomain); */ void _IL_AppDomain_UnloadAppDomain(ILExecThread *thread, ILObject *appDomain) { if(!IsAppDomainUnloaded(thread, (ILExecProcess *)appDomain)) { #ifdef IL_CONFIG_APPDOMAINS if (appDomain) { ILExecEngine *engine = ILExecEngineInstance(); if (engine) /* this should always be true */ { /* we aren't allowed to unload the default AppDomain */ if ((ILExecProcess *)appDomain == engine->defaultProcess) { /* bail out */ /* Throw an CannotUnloadAppDomainException */ ILExecThreadThrowSystem(thread, "System.CannotUnloadAppDomainException", (const char *)0); return; } /* if the current thread runs in the specified process */ /* we need to start an other thread to do the Unload */ if (thread->process == (ILExecProcess *)appDomain) { /* TODO */ } ILExecProcessUnload((ILExecProcess *)appDomain); } } #else /* we don't support multiple Appdomains so there is nothing to do */ #endif } }
/* * Destroy the engine. */ void ILExecEngineDestroy(ILExecEngine *engine) { int count; ILExecProcess *process; ILQueueEntry *unloadQueue, *destroyQueue; unloadQueue = ILQueueCreate(); destroyQueue = ILQueueCreate(); /* Lock the engine process list*/ ILMutexLock(engine->processLock); count = 0; /* Walk all the application domains and collect them */ process = engine->firstProcess; while (process) { if (process != engine->defaultProcess) { if(process->state < _IL_PROCESS_STATE_UNLOADING) { ILQueueAdd(&unloadQueue, process); } ILQueueAdd(&destroyQueue, process); count++; } /* Move onto the next process */ process = process->nextProcess; } /* Unlock the engine process list */ ILMutexUnlock(engine->processLock); if ((!unloadQueue || !destroyQueue) && count != 0) { /* Probably ran out of memory trying to build the unload and destroy queue */ return; } /* unload all processes */ while (unloadQueue) { process = (ILExecProcess *)ILQueueRemove(&unloadQueue); ILExecProcessUnload(process); } /* now destroy the processes */ while (destroyQueue) { process = (ILExecProcess *)ILQueueRemove(&destroyQueue); ILExecProcessDestroy(process); } /* now unload and destroy the default process */ if(engine->defaultProcess) { ILExecProcessUnload(engine->defaultProcess); ILExecProcessDestroy(engine->defaultProcess); } if (engine->processLock) { /* Destroy the process list lock */ ILMutexDestroy(engine->processLock); } /* Free the engine block itself */ ILGCFreePersistent(engine); }