mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-28 15:34:33 +00:00
Improved shutting down procedure
This commit is contained in:
parent
ffdbc6e598
commit
3f166b97c7
@ -47,7 +47,7 @@ void KernelMainThread()
|
|||||||
KPrint("Initializing Network Interface Manager...");
|
KPrint("Initializing Network Interface Manager...");
|
||||||
NIManager = new NetworkInterfaceManager::NetworkInterface;
|
NIManager = new NetworkInterfaceManager::NetworkInterface;
|
||||||
KPrint("Starting Network Interface Manager...");
|
KPrint("Starting Network Interface Manager...");
|
||||||
// NIManager->StartService();
|
NIManager->StartService();
|
||||||
|
|
||||||
KPrint("Setting up userspace...");
|
KPrint("Setting up userspace...");
|
||||||
|
|
||||||
@ -91,10 +91,7 @@ Exit:
|
|||||||
|
|
||||||
void KernelShutdownThread(bool Reboot)
|
void KernelShutdownThread(bool Reboot)
|
||||||
{
|
{
|
||||||
delete NIManager;
|
BeforeShutdown();
|
||||||
|
|
||||||
if (DriverManager)
|
|
||||||
DriverManager->UnloadAllDrivers();
|
|
||||||
|
|
||||||
trace("Shutting Down/Rebooting...");
|
trace("Shutting Down/Rebooting...");
|
||||||
if (Reboot)
|
if (Reboot)
|
||||||
|
24
Kernel.cpp
24
Kernel.cpp
@ -30,11 +30,11 @@
|
|||||||
*
|
*
|
||||||
* BUGS:
|
* BUGS:
|
||||||
* - [ ] Kernel crashes when receiving interrupts for drivers only if the system has one core and the tasking is running.
|
* - [ ] Kernel crashes when receiving interrupts for drivers only if the system has one core and the tasking is running.
|
||||||
*
|
*
|
||||||
* CREDITS AND REFERENCES:
|
* CREDITS AND REFERENCES:
|
||||||
* - General:
|
* - General:
|
||||||
* https://wiki.osdev.org/Main_Page
|
* https://wiki.osdev.org/Main_Page
|
||||||
*
|
*
|
||||||
* - Network:
|
* - Network:
|
||||||
* https://web.archive.org/web/20051210132103/http://users.pcnet.ro/dmoroian/beej/Beej.html
|
* https://web.archive.org/web/20051210132103/http://users.pcnet.ro/dmoroian/beej/Beej.html
|
||||||
* https://web.archive.org/web/20060229214053/http://www.cs.rutgers.edu/~pxk/417/notes/sockets/udp.html
|
* https://web.archive.org/web/20060229214053/http://www.cs.rutgers.edu/~pxk/417/notes/sockets/udp.html
|
||||||
@ -248,6 +248,26 @@ EXTERNC __no_stack_protector __no_instrument_function void Entry(BootInfo *Info)
|
|||||||
|
|
||||||
EXTERNC __no_stack_protector __no_instrument_function void BeforeShutdown()
|
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
|
// https://wiki.osdev.org/Calling_Global_Constructors
|
||||||
debug("Calling destructors...");
|
debug("Calling destructors...");
|
||||||
for (CallPtr *func = __fini_array_start; func != __fini_array_end; func++)
|
for (CallPtr *func = __fini_array_start; func != __fini_array_end; func++)
|
||||||
|
@ -743,6 +743,13 @@ namespace Tasking
|
|||||||
OneShot(1);
|
OneShot(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Task::SignalShutdown()
|
||||||
|
{
|
||||||
|
fixme("SignalShutdown()");
|
||||||
|
// TODO: Implement this
|
||||||
|
// This should hang until all processes are terminated
|
||||||
|
}
|
||||||
|
|
||||||
TCB *Task::CreateThread(PCB *Parent,
|
TCB *Task::CreateThread(PCB *Parent,
|
||||||
IP EntryPoint,
|
IP EntryPoint,
|
||||||
const char **argv,
|
const char **argv,
|
||||||
@ -1210,5 +1217,34 @@ namespace Tasking
|
|||||||
{
|
{
|
||||||
SmartCriticalSection(TaskingLock);
|
SmartCriticalSection(TaskingLock);
|
||||||
trace("Stopping tasking");
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,6 +267,7 @@ namespace Tasking
|
|||||||
Vector<PCB *> GetProcessList() { return ListProcess; }
|
Vector<PCB *> GetProcessList() { return ListProcess; }
|
||||||
void Panic() { StopScheduler = true; }
|
void Panic() { StopScheduler = true; }
|
||||||
void Schedule();
|
void Schedule();
|
||||||
|
void SignalShutdown();
|
||||||
long GetUsage(int Core)
|
long GetUsage(int Core)
|
||||||
{
|
{
|
||||||
if (IdleProcess)
|
if (IdleProcess)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user