diff --git a/KThread.cpp b/KThread.cpp index 0a83940..530e531 100644 --- a/KThread.cpp +++ b/KThread.cpp @@ -178,7 +178,7 @@ void BootLogoAnimationThread() if (!stbi_info_from_memory((uint8_t *)Frames[i], FrameSizes[i], &x, &y, &channels)) continue; - uint8_t *img = stbi_load_from_memory((uint8_t *)Frames[i], FrameSizes[i], &x, &y, &channels, 4); + uint8_t *img = stbi_load_from_memory((uint8_t *)Frames[i], FrameSizes[i], &x, &y, &channels, STBI_rgb_alpha); if (img == NULL) continue; @@ -233,7 +233,7 @@ void ExitLogoAnimationThread() if (!stbi_info_from_memory((uint8_t *)Frames[i], FrameSizes[i], &x, &y, &channels)) continue; - uint8_t *img = stbi_load_from_memory((uint8_t *)Frames[i], FrameSizes[i], &x, &y, &channels, 4); + uint8_t *img = stbi_load_from_memory((uint8_t *)Frames[i], FrameSizes[i], &x, &y, &channels, STBI_rgb_alpha); if (img == NULL) continue; @@ -272,8 +272,13 @@ void ExitLogoAnimationThread() } } +void CleanupProcessesThreadWrapper() { TaskManager->CleanupProcessesThread(); } + void KernelMainThread() { + Tasking::TCB *clnThd = TaskManager->CreateThread(TaskManager->GetCurrentProcess(), (Tasking::IP)CleanupProcessesThreadWrapper); + clnThd->SetPriority(Tasking::Idle); + TaskManager->SetCleanupThread(clnThd); TaskManager->GetCurrentThread()->SetPriority(Tasking::Critical); Tasking::TCB *blaThread = nullptr; diff --git a/Tasking/Scheduler.cpp b/Tasking/Scheduler.cpp index f31b342..31b894d 100644 --- a/Tasking/Scheduler.cpp +++ b/Tasking/Scheduler.cpp @@ -270,16 +270,6 @@ namespace Tasking return false; } - SafeFunction NIF void Task::SchedulerCleanupProcesses() - { - foreach (auto process in ListProcess) - { - if (InvalidPCB(process)) - continue; - RemoveProcess(process); - } - } - SafeFunction NIF bool Task::SchedulerSearchProcessThread(void *CPUDataPointer) { CPUData *CurrentCPU = (CPUData *)CPUDataPointer; @@ -546,9 +536,6 @@ namespace Tasking } schedbg("Passed GetNextAvailableProcess"); - this->SchedulerCleanupProcesses(); - schedbg("Passed SchedulerCleanupProcesses"); - if (SchedulerSearchProcessThread(CurrentCPU)) { #ifdef ON_SCREEN_SCHEDULER_TASK_MANAGER @@ -690,11 +677,6 @@ namespace Tasking fixme("unimplemented"); } - SafeFunction void Task::SchedulerCleanupProcesses() - { - fixme("unimplemented"); - } - SafeFunction bool Task::SchedulerSearchProcessThread(void *CPUDataPointer) { fixme("unimplemented"); @@ -722,11 +704,6 @@ namespace Tasking fixme("unimplemented"); } - SafeFunction void Task::SchedulerCleanupProcesses() - { - fixme("unimplemented"); - } - SafeFunction bool Task::SchedulerSearchProcessThread(void *CPUDataPointer) { fixme("unimplemented"); diff --git a/Tasking/Task.cpp b/Tasking/Task.cpp index da4e308..c5adc3b 100644 --- a/Tasking/Task.cpp +++ b/Tasking/Task.cpp @@ -284,6 +284,21 @@ namespace Tasking // This should hang until all processes are terminated } + void Task::CleanupProcessesThread() + { + while (true) + { + this->Sleep(1000); + foreach (auto process in ListProcess) + { + if (InvalidPCB(process)) + continue; + + RemoveProcess(process); + } + } + } + void Task::RevertProcessCreation(PCB *Process) { for (size_t i = 0; i < ListProcess.size(); i++) @@ -837,35 +852,24 @@ namespace Tasking Task::~Task() { debug("Destructor called"); - SmartLock(TaskingLock); - trace("Stopping tasking"); - /*size_t ExpectedToBeTerminated = 0; - foreach (PCB *Process in ListProcess) { - foreach (TCB *Thread in Process->Threads) + SmartLock(TaskingLock); + foreach (PCB *Process in ListProcess) { - if (Thread == GetCurrentCPU()->CurrentThread.Load()) + foreach (TCB *Thread in Process->Threads) + { + if (Thread == GetCurrentCPU()->CurrentThread.Load() || + Thread == CleanupThread) + continue; + this->KillThread(Thread, 0xFFFF); + } + + if (Process == GetCurrentCPU()->CurrentProcess.Load()) continue; - this->KillThread(Thread, 0xFFFF); - ExpectedToBeTerminated++; + this->KillProcess(Process, 0xFFFF); } - - if (Process == GetCurrentCPU()->CurrentProcess.Load()) - continue; - this->KillProcess(Process, 0xFFFF); - ExpectedToBeTerminated++; - }*/ - - foreach (PCB *Process in ListProcess) - { - foreach (TCB *Thread in Process->Threads) - Thread->Status = TaskStatus::Terminated; - - Process->Status = TaskStatus::Terminated; } - TaskingLock.Unlock(); - while (ListProcess.size() > 0) { trace("Waiting for %d processes to terminate", ListProcess.size()); @@ -877,7 +881,7 @@ namespace Tasking continue; NotTerminated++; } - if (NotTerminated == 0 /*1*/) + if (NotTerminated == 1) break; TaskingScheduler_OneShot(100); } diff --git a/include/task.hpp b/include/task.hpp index 6b9e273..3c27347 100644 --- a/include/task.hpp +++ b/include/task.hpp @@ -229,9 +229,10 @@ namespace Tasking std::vector ListProcess; PCB *IdleProcess = nullptr; TCB *IdleThread = nullptr; + TCB *CleanupThread = nullptr; Atomic SchedulerTicks = 0; Atomic LastTaskTicks = 0; - + bool StopScheduler = false; bool InvalidPCB(PCB *pcb); bool InvalidTCB(TCB *tcb); @@ -245,7 +246,6 @@ namespace Tasking bool FindNewProcess(void *CPUDataPointer); bool GetNextAvailableThread(void *CPUDataPointer); bool GetNextAvailableProcess(void *CPUDataPointer); - void SchedulerCleanupProcesses(); bool SchedulerSearchProcessThread(void *CPUDataPointer); void UpdateProcessStatus(); void WakeUpThreads(void *CPUDataPointer); @@ -260,13 +260,14 @@ namespace Tasking void Schedule(void *Frame); void OnInterruptReceived(void *Frame); #endif - bool StopScheduler = false; public: + void SetCleanupThread(TCB *Thread) { CleanupThread = Thread; } uint64_t GetSchedulerTicks() { return SchedulerTicks.Load(); } uint64_t GetLastTaskTicks() { return LastTaskTicks.Load(); } std::vector GetProcessList() { return ListProcess; } Security *GetSecurityManager() { return &SecurityManager; } + void CleanupProcessesThread(); void Panic() { StopScheduler = true; } void Schedule(); void SignalShutdown();