fix: add start pending mode to mitigate Terminal output redirection issue
This commit is contained in:
@@ -175,6 +175,7 @@ namespace Sched {
|
||||
processTable[i].runningOnCpu = -1;
|
||||
processTable[i].killPending = false;
|
||||
processTable[i].reapReady = false;
|
||||
processTable[i].startPending = false;
|
||||
processTable[i].waitingForPid = -1;
|
||||
processTable[i].sleepUntilTick = 0;
|
||||
processTable[i].waitingOnObject = nullptr;
|
||||
@@ -203,7 +204,7 @@ namespace Sched {
|
||||
<< " process slots, " << (uint64_t)TimeSliceMs << " ms time slice)";
|
||||
}
|
||||
|
||||
int Spawn(const char* vfsPath, const char* args) {
|
||||
int Spawn(const char* vfsPath, const char* args, bool startReady) {
|
||||
schedLock.Acquire();
|
||||
|
||||
int slot = -1;
|
||||
@@ -343,8 +344,9 @@ namespace Sched {
|
||||
|
||||
Process& proc = processTable[slot];
|
||||
proc.pid = nextPid++;
|
||||
proc.state = ProcessState::Ready;
|
||||
readyCount++;
|
||||
proc.state = startReady ? ProcessState::Ready : ProcessState::Blocked;
|
||||
if (startReady)
|
||||
readyCount++;
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < 63 && vfsPath[i]; i++) proc.name[i] = vfsPath[i];
|
||||
@@ -363,6 +365,7 @@ namespace Sched {
|
||||
proc.runningOnCpu = -1;
|
||||
proc.killPending = false;
|
||||
proc.reapReady = false;
|
||||
proc.startPending = !startReady;
|
||||
proc.waitingForPid = -1;
|
||||
proc.sleepUntilTick = 0;
|
||||
proc.waitingOnObject = nullptr;
|
||||
@@ -436,11 +439,39 @@ namespace Sched {
|
||||
|
||||
int resultPid = proc.pid;
|
||||
schedLock.Release();
|
||||
KickOneIdleCpu(Smp::GetCurrentCpuData() ? Smp::GetCurrentCpuData()->cpuIndex : -1);
|
||||
if (startReady)
|
||||
KickOneIdleCpu(Smp::GetCurrentCpuData() ? Smp::GetCurrentCpuData()->cpuIndex : -1);
|
||||
|
||||
return resultPid;
|
||||
}
|
||||
|
||||
int StartProcess(int pid) {
|
||||
if (pid < 0) return -1;
|
||||
|
||||
schedLock.Acquire();
|
||||
for (int i = 0; i < MaxProcesses; i++) {
|
||||
if (processTable[i].pid != pid) continue;
|
||||
if (processTable[i].state != ProcessState::Blocked ||
|
||||
!processTable[i].startPending) {
|
||||
schedLock.Release();
|
||||
return -1;
|
||||
}
|
||||
|
||||
processTable[i].startPending = false;
|
||||
processTable[i].waitingForPid = -1;
|
||||
processTable[i].sleepUntilTick = 0;
|
||||
processTable[i].waitingOnObject = nullptr;
|
||||
processTable[i].state = ProcessState::Ready;
|
||||
readyCount++;
|
||||
schedLock.Release();
|
||||
KickOneIdleCpu(Smp::GetCurrentCpuData() ? Smp::GetCurrentCpuData()->cpuIndex : -1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
schedLock.Release();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
// Schedule -- core context switch logic
|
||||
//
|
||||
@@ -470,6 +501,7 @@ namespace Sched {
|
||||
processTable[i].stackBase = 0;
|
||||
processTable[i].pml4Phys = 0;
|
||||
processTable[i].reapReady = false;
|
||||
processTable[i].startPending = false;
|
||||
processTable[i].state = ProcessState::Free;
|
||||
|
||||
// Release lock during PFA::Free to minimize hold time
|
||||
@@ -683,6 +715,7 @@ namespace Sched {
|
||||
|
||||
Process& proc = processTable[slot];
|
||||
proc.killPending = false;
|
||||
proc.startPending = false;
|
||||
int exitingPid = proc.pid;
|
||||
|
||||
// Clean up any windows owned by this process
|
||||
@@ -823,6 +856,7 @@ namespace Sched {
|
||||
readyCount--;
|
||||
proc.state = ProcessState::Terminated;
|
||||
proc.killPending = false;
|
||||
proc.startPending = false;
|
||||
proc.reapReady = false;
|
||||
proc.waitingForPid = -1;
|
||||
proc.sleepUntilTick = 0;
|
||||
|
||||
Reference in New Issue
Block a user