Improved shutting down procedure

This commit is contained in:
Alex 2022-12-29 05:25:43 +02:00
parent ffdbc6e598
commit 3f166b97c7
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
4 changed files with 61 additions and 7 deletions

View File

@ -47,7 +47,7 @@ void KernelMainThread()
KPrint("Initializing Network Interface Manager...");
NIManager = new NetworkInterfaceManager::NetworkInterface;
KPrint("Starting Network Interface Manager...");
// NIManager->StartService();
NIManager->StartService();
KPrint("Setting up userspace...");
@ -91,10 +91,7 @@ Exit:
void KernelShutdownThread(bool Reboot)
{
delete NIManager;
if (DriverManager)
DriverManager->UnloadAllDrivers();
BeforeShutdown();
trace("Shutting Down/Rebooting...");
if (Reboot)

View File

@ -248,6 +248,26 @@ EXTERNC __no_stack_protector __no_instrument_function void Entry(BootInfo *Info)
EXTERNC __no_stack_protector __no_instrument_function void BeforeShutdown()
{
/* TODO: Announce shutdown */
trace("\n\n\n#################### SYSTEM SHUTTING DOWN ####################\n\n");
delete NIManager;
delete DiskManager;
if (DriverManager)
DriverManager->UnloadAllDrivers();
delete DriverManager;
TaskManager->SignalShutdown();
delete TaskManager;
delete RecoveryScreen;
delete vfs;
delete TimeManager;
delete KernelSymbolTable;
delete Display;
// PowerManager should not be called
// https://wiki.osdev.org/Calling_Global_Constructors
debug("Calling destructors...");
for (CallPtr *func = __fini_array_start; func != __fini_array_end; func++)

View File

@ -743,6 +743,13 @@ namespace Tasking
OneShot(1);
}
void Task::SignalShutdown()
{
fixme("SignalShutdown()");
// TODO: Implement this
// This should hang until all processes are terminated
}
TCB *Task::CreateThread(PCB *Parent,
IP EntryPoint,
const char **argv,
@ -1210,5 +1217,34 @@ namespace Tasking
{
SmartCriticalSection(TaskingLock);
trace("Stopping tasking");
foreach (auto Process in ListProcess)
{
for (auto &Thread : Process->Threads)
{
Thread->Status = TaskStatus::Terminated;
}
Process->Status = TaskStatus::Terminated;
}
TaskingLock.Unlock();
SchedulerLock.Unlock();
while (ListProcess.size() > 0)
{
trace("Waiting for %d processes to terminate", ListProcess.size());
int NotTerminated = 0;
foreach (auto Process in ListProcess)
{
debug("Process %s(%d) is still running (or waiting to be removed status %#lx)", Process->Name, Process->ID, Process->Status);
if (Process->Status == TaskStatus::Terminated)
continue;
NotTerminated++;
}
if (NotTerminated == 0)
break;
OneShot(100);
}
trace("Tasking stopped");
}
}

View File

@ -267,6 +267,7 @@ namespace Tasking
Vector<PCB *> GetProcessList() { return ListProcess; }
void Panic() { StopScheduler = true; }
void Schedule();
void SignalShutdown();
long GetUsage(int Core)
{
if (IdleProcess)