summaryrefslogtreecommitdiffhomepage
path: root/Kernel
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-05-17 22:25:04 +0200
committerAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-05-17 22:25:04 +0200
commitc0428f8e5feba9573e572a1a1b3c66cfa1f29108 (patch)
treea0ecdb03c667558133a23cd7cb546a3e84489659 /Kernel
parent9ebaf586257bf42996881b70a79cb2d57d8fd1ef (diff)
MHR-23: Improve scheduler code.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/KernelKit/ProcessScheduler.hpp12
-rw-r--r--Kernel/Source/ProcessScheduler.cxx46
2 files changed, 42 insertions, 16 deletions
diff --git a/Kernel/KernelKit/ProcessScheduler.hpp b/Kernel/KernelKit/ProcessScheduler.hpp
index 243857ae..9768d56a 100644
--- a/Kernel/KernelKit/ProcessScheduler.hpp
+++ b/Kernel/KernelKit/ProcessScheduler.hpp
@@ -252,23 +252,25 @@ namespace NewOS
{
return mTeam.AsArray().Count() > 0;
}
+
bool operator!()
{
return mTeam.AsArray().Count() == 0;
}
- ProcessTeam& CurrentTeam()
- {
- return mTeam;
- }
+ public:
+ ProcessTeam& CurrentTeam();
+ public:
SizeT Add(Ref<ProcessHeader>& headerRef);
bool Remove(SizeT headerIndex);
+ public:
Ref<ProcessHeader>& GetCurrent();
SizeT Run() noexcept;
- static Ref<ProcessScheduler> Shared();
+ public:
+ static Ref<ProcessScheduler&> Shared();
private:
ProcessTeam mTeam;
diff --git a/Kernel/Source/ProcessScheduler.cxx b/Kernel/Source/ProcessScheduler.cxx
index 555dfe07..22e1fb4d 100644
--- a/Kernel/Source/ProcessScheduler.cxx
+++ b/Kernel/Source/ProcessScheduler.cxx
@@ -150,16 +150,16 @@ namespace NewOS
/***********************************************************************************/
/**
-@brief Affinity is the time slot allowed for the process.
-*/
+ @brief Affinity is the time slot allowed for the process.
+ */
const AffinityKind& ProcessHeader::GetAffinity()
{
return this->Affinity;
}
/**
-@brief Standard exit proc.
-*/
+ @brief Standard exit proc.
+ */
void ProcessHeader::Exit(Int32 exit_code)
{
if (this->ProcessId !=
@@ -196,6 +196,9 @@ namespace NewOS
ProcessScheduler::Shared().Leak().Remove(this->ProcessId);
}
+ /// @brief Add process to list.
+ /// @param process
+ /// @return
SizeT ProcessScheduler::Add(Ref<ProcessHeader>& process)
{
if (!process)
@@ -238,6 +241,9 @@ namespace NewOS
return mTeam.AsArray().Count() - 1;
}
+ /// @brief Remove process from list.
+ /// @param process
+ /// @return
bool ProcessScheduler::Remove(SizeT process)
{
if (process > mTeam.AsArray().Count())
@@ -248,6 +254,8 @@ namespace NewOS
return mTeam.AsArray().Remove(process);
}
+ /// @brief Run scheduler.
+ /// @return
SizeT ProcessScheduler::Run() noexcept
{
SizeT processIndex = 0; //! we store this guy to tell the scheduler how many
@@ -284,7 +292,16 @@ namespace NewOS
return processIndex;
}
- Ref<ProcessScheduler> ProcessScheduler::Shared()
+ /// @brief Gets the current scheduled team.
+ /// @return
+ ProcessTeam& ProcessScheduler::CurrentTeam()
+ {
+ return mTeam;
+ }
+
+ /// @brief Shared instance of the process scheduler.
+ /// @return
+ Ref<ProcessScheduler&> ProcessScheduler::Shared()
{
static ProcessScheduler ref;
return {ref};
@@ -297,12 +314,18 @@ namespace NewOS
return mTeam.AsRef();
}
+ /// @brief Current proccess id getter.
+ /// @return Process ID integer.
PID& ProcessHelper::GetCurrentPID()
{
kcout << "ProcessHelper::GetCurrentPID: Leaking ProcessId...\r";
return ProcessScheduler::Shared().Leak().GetCurrent().Leak().ProcessId;
}
+ /// @brief Check if process can be schedulded.
+ /// @param process the process reference.
+ /// @retval true can be schedulded.
+ /// @retval false cannot be schedulded.
bool ProcessHelper::CanBeScheduled(Ref<ProcessHeader>& process)
{
if (process.Leak().Status == ProcessStatus::kFrozen ||
@@ -326,8 +349,9 @@ namespace NewOS
}
/**
- * @brief Spin scheduler class.
- */
+ * @brief Spin scheduler class.
+ */
+
bool ProcessHelper::StartScheduling()
{
if (ProcessHelper::CanBeScheduled(
@@ -351,10 +375,10 @@ namespace NewOS
}
/**
- * \brief Does a context switch in a CPU.
- * \param the_stack the stackframe of the running app.
- * \param new_pid the process's PID.
-*/
+ * \brief Does a context switch in a CPU.
+ * \param the_stack the stackframe of the running app.
+ * \param new_pid the process's PID.
+ */
bool ProcessHelper::Switch(HAL::StackFrame* the_stack, const PID& new_pid)
{