summaryrefslogtreecommitdiffhomepage
path: root/Kernel/Sources/ProcessScheduler.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel/Sources/ProcessScheduler.cxx')
-rw-r--r--Kernel/Sources/ProcessScheduler.cxx45
1 files changed, 24 insertions, 21 deletions
diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx
index d9d013c6..dc273cf6 100644
--- a/Kernel/Sources/ProcessScheduler.cxx
+++ b/Kernel/Sources/ProcessScheduler.cxx
@@ -59,18 +59,20 @@ namespace NewOS
VoidPtr ProcessHeader::New(const SizeT& sz)
{
- if (this->FreeMemory < 1)
+ if (this->HeapCursor)
{
- DbgLastError() = kErrorHeapOutOfMemory;
- this->Crash(); /// out of memory.
+ if (this->FreeMemory < 1)
+ {
+ DbgLastError() = kErrorHeapOutOfMemory;
+
+ /* we're going out of memory */
+ this->Crash();
- return nullptr;
- }
+ return nullptr;
+ }
- if (this->HeapCursor)
- {
- VoidPtr ptr = this->HeapCursor;
this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor + (sizeof(sz)));
+ VoidPtr ptr = this->HeapCursor;
++this->UsedMemory;
--this->FreeMemory;
@@ -206,12 +208,14 @@ namespace NewOS
ke_new_ke_heap(sizeof(HAL::StackFrame), true, false));
MUST_PASS(process.Leak().StackFrame);
+
+ process.Leak().Status = ProcessStatus::kRunning;
- mTeam.AsArray().Add(process);
-
- process.Leak().ProcessId = mTeam.AsArray().Count() - 1;
+ process.Leak().ProcessId = (mTeam.AsArray().Count() - 1);
process.Leak().HeapCursor = process.Leak().HeapPtr;
+ mTeam.AsArray().Add(process);
+
return mTeam.AsArray().Count() - 1;
}
@@ -232,17 +236,14 @@ namespace NewOS
/// @return
SizeT ProcessScheduler::Run() noexcept
{
- SizeT processIndex = 0; //! we store this guy to tell the scheduler how many
+ SizeT process_index = 0; //! we store this guy to tell the scheduler how many
//! things we have scheduled.
- for (; processIndex < mTeam.AsArray().Count(); ++processIndex)
+ for (; process_index < mTeam.AsArray().Count(); ++process_index)
{
- auto process = mTeam.AsArray()[processIndex];
-
- if (!process)
- continue;
+ auto process = mTeam.AsArray()[process_index];
- //! run any process needed to be scheduled.
+ //! check if process needs to be scheduled.
if (ProcessHelper::CanBeScheduled(process.Leak()))
{
auto unwrapped_process = *process.Leak();
@@ -255,6 +256,8 @@ namespace NewOS
// tell helper to find a core to schedule on.
ProcessHelper::Switch(mTeam.AsRef().Leak().StackFrame,
mTeam.AsRef().Leak().ProcessId);
+
+ kcout << unwrapped_process.Name << ": process switched.\r";
}
else
{
@@ -263,7 +266,7 @@ namespace NewOS
}
}
- return processIndex;
+ return process_index;
}
/// @brief Gets the current scheduled team.
@@ -328,8 +331,8 @@ namespace NewOS
bool ProcessHelper::StartScheduling()
{
- auto& processRef = ProcessScheduler::The().Leak();
- SizeT ret = processRef.Run();
+ auto& process_ref = ProcessScheduler::The().Leak();
+ SizeT ret = process_ref.Run();
kcout << "newoskrnl: Iterated over: ";
kcout.Number(ret);