mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-28 15:34:33 +00:00
Process cleanup should be done by a thread
This commit is contained in:
parent
fe64c55afc
commit
1266764aec
@ -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;
|
||||
|
@ -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");
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -229,9 +229,10 @@ namespace Tasking
|
||||
std::vector<PCB *> ListProcess;
|
||||
PCB *IdleProcess = nullptr;
|
||||
TCB *IdleThread = nullptr;
|
||||
TCB *CleanupThread = nullptr;
|
||||
Atomic<uint64_t> SchedulerTicks = 0;
|
||||
Atomic<uint64_t> 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<PCB *> GetProcessList() { return ListProcess; }
|
||||
Security *GetSecurityManager() { return &SecurityManager; }
|
||||
void CleanupProcessesThread();
|
||||
void Panic() { StopScheduler = true; }
|
||||
void Schedule();
|
||||
void SignalShutdown();
|
||||
|
Loading…
x
Reference in New Issue
Block a user