summaryrefslogtreecommitdiffhomepage
path: root/Private/Source/SMPManager.cxx
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-29 18:17:47 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-29 18:18:59 +0100
commit65254486efff0fd1bb78a48ff90b7713a5ce539f (patch)
tree20ce02c12a74ba9e6cd382bf9c1f09a0c611cb4d /Private/Source/SMPManager.cxx
parentf03986937db0b927da4b10554801e18e4dc7c43f (diff)
Kernel: Update TODO.
Src: Refactorings according to clang-format. Meta: Update specification. Public: Remove useless UIKit. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/Source/SMPManager.cxx')
-rw-r--r--Private/Source/SMPManager.cxx203
1 files changed, 98 insertions, 105 deletions
diff --git a/Private/Source/SMPManager.cxx b/Private/Source/SMPManager.cxx
index 4897165b..05e47ea8 100644
--- a/Private/Source/SMPManager.cxx
+++ b/Private/Source/SMPManager.cxx
@@ -7,144 +7,137 @@
* ========================================================
*/
-#include <KernelKit/SMPManager.hpp>
-#include <KernelKit/ProcessManager.hpp>
#include <ArchKit/Arch.hpp>
+#include <KernelKit/ProcessManager.hpp>
+#include <KernelKit/SMPManager.hpp>
/// BUGS: 0
//! This file handles multi processing in hCore.
//! Multi processing is needed for File I/O, networking and scheduling.
-namespace hCore
-{
- // A ProcessorCore class takes care of it's owned hardware thread.
- // It has a stack for it's core.
+namespace hCore {
+// A ProcessorCore class takes care of it's owned hardware thread.
+// It has a stack for it's core.
+
+// @brief constructor
+ProcessorCore::ProcessorCore() = default;
+
+// @brief destructor
+ProcessorCore::~ProcessorCore() = default;
+
+//! @brief returns the id
- // @brief constructor
- ProcessorCore::ProcessorCore() = default;
+const ThreadID& ProcessorCore::ID() noexcept { return m_ID; }
- // @brief destructor
- ProcessorCore::~ProcessorCore() = default;
-
- //! @brief returns the id
+//! @brief returns the kind
- const ThreadID& ProcessorCore::ID() noexcept { return m_ID; }
-
- //! @brief returns the kind
+const ThreadKind& ProcessorCore::Kind() noexcept { return m_Kind; }
- const ThreadKind& ProcessorCore::Kind() noexcept { return m_Kind; }
+//! @brief is the core busy?
- //! @brief is the core busy?
+bool ProcessorCore::IsBusy() noexcept { return m_Busy; }
- bool ProcessorCore::IsBusy() noexcept { return m_Busy; }
+/// @brief Get processor stack frame.
- /// @brief Get processor stack frame.
+HAL::StackFrame* ProcessorCore::StackFrame() noexcept {
+ MUST_PASS(m_Stack);
+ return m_Stack;
+}
- HAL::StackFrame* ProcessorCore::StackFrame() noexcept
- {
- MUST_PASS(m_Stack);
- return m_Stack;
- }
+void ProcessorCore::Busy(const bool busy) noexcept { m_Busy = busy; }
- void ProcessorCore::Busy(const bool busy) noexcept { m_Busy = busy; }
+ProcessorCore::operator bool() { return m_Stack; }
- ProcessorCore::operator bool() { return m_Stack; }
+/// @brief Wakeup the processor.
- /// @brief Wakeup the processor.
+void ProcessorCore::Wake(const bool wakeup) noexcept {
+ m_Wakeup = wakeup;
- void ProcessorCore::Wake(const bool wakeup) noexcept
- {
- m_Wakeup = wakeup;
+ if (!m_Wakeup)
+ rt_hang_thread(m_Stack);
+ else
+ rt_wakeup_thread(m_Stack);
+}
- if (!m_Wakeup)
- rt_hang_thread(m_Stack);
- else
- rt_wakeup_thread(m_Stack);
- }
+bool ProcessorCore::Switch(HAL::StackFrame* stack) {
+ if (stack == nullptr) return false;
- bool ProcessorCore::Switch(HAL::StackFrame* stack)
- {
- if (stack == nullptr)
- return false;
+ return rt_do_context_switch(m_Stack, stack) == 0;
+}
- return rt_do_context_switch(m_Stack, stack) == 0;
- }
+///! @brief Tells if processor is waked up.
+bool ProcessorCore::IsWakeup() noexcept { return m_Wakeup; }
- ///! @brief Tells if processor is waked up.
- bool ProcessorCore::IsWakeup() noexcept { return m_Wakeup; }
+//! @brief Constructor and destructor
- //! @brief Constructor and destructor
+///! @brief Default constructor.
+SMPManager::SMPManager() = default;
- ///! @brief Default constructor.
- SMPManager::SMPManager() = default;
+///! @brief Default destructor.
+SMPManager::~SMPManager() = default;
- ///! @brief Default destructor.
- SMPManager::~SMPManager() = default;
+/// @brief Shared singleton function
+Ref<SMPManager> SMPManager::Shared() {
+ static SMPManager manager;
+ return {manager};
+}
- /// @brief Shared singleton function
- Ref<SMPManager> SMPManager::Shared()
- {
- static SMPManager manager;
- return { manager };
- }
+/// @brief Get Stack Frame of Core
+HAL::StackFramePtr SMPManager::GetStackFrame() noexcept {
+ if (m_ThreadList[m_CurrentThread].Leak() &&
+ ProcessHelper::GetCurrentPID() ==
+ m_ThreadList[m_CurrentThread].Leak().Leak().m_PID)
+ return m_ThreadList[m_CurrentThread].Leak().Leak().m_Stack;
- /// @brief Get Stack Frame of Core
- HAL::StackFramePtr SMPManager::GetStackFrame() noexcept
- {
- if (m_ThreadList[m_CurrentThread].Leak() &&
- ProcessHelper::GetCurrentPID() == m_ThreadList[m_CurrentThread].Leak().Leak().m_PID)
- return m_ThreadList[m_CurrentThread].Leak().Leak().m_Stack;
+ return nullptr;
+}
- return nullptr;
- }
+/// @brief Finds and switch to a free core.
+bool SMPManager::Switch(HAL::StackFrame* stack) {
+ if (stack == nullptr) return false;
- /// @brief Finds and switch to a free core.
- bool SMPManager::Switch(HAL::StackFrame* stack)
- {
- if (stack == nullptr)
- return false;
+ for (SizeT idx = 0; idx < kMaxHarts; ++idx) {
+ // stack != nullptr -> if core is used, then continue.
+ if (!m_ThreadList[idx].Leak() ||
+ !m_ThreadList[idx].Leak().Leak().IsWakeup() ||
+ m_ThreadList[idx].Leak().Leak().IsBusy())
+ continue;
- for (SizeT idx = 0; idx < kMaxHarts; ++idx)
- {
- // stack != nullptr -> if core is used, then continue.
- if (!m_ThreadList[idx].Leak() ||
- !m_ThreadList[idx].Leak().Leak().IsWakeup() ||
- m_ThreadList[idx].Leak().Leak().IsBusy())
- continue;
+ m_ThreadList[idx].Leak().Leak().m_ID = idx;
+ m_ThreadList[idx].Leak().Leak().m_Stack = stack;
+ m_ThreadList[idx].Leak().Leak().m_PID = ProcessHelper::GetCurrentPID();
- m_ThreadList[idx].Leak().Leak().m_ID = idx;
- m_ThreadList[idx].Leak().Leak().m_Stack = stack;
- m_ThreadList[idx].Leak().Leak().m_PID = ProcessHelper::GetCurrentPID();
-
- m_ThreadList[idx].Leak().Leak().Busy(true);
+ m_ThreadList[idx].Leak().Leak().Busy(true);
- Boolean ret = (rt_do_context_switch(rt_get_current_context(), stack) == 0);
-
- m_ThreadList[idx].Leak().Leak().Busy(false);
+ Boolean ret = (rt_do_context_switch(rt_get_current_context(), stack) == 0);
- return ret;
- }
+ m_ThreadList[idx].Leak().Leak().Busy(false);
- return false;
- }
+ return ret;
+ }
- /**
- * Index hart
- * @param idx
- * @return
- */
- Ref<ProcessorCore> SMPManager::operator[](const SizeT& idx) { return m_ThreadList[idx].Leak(); }
-
- /**
- * Check if thread pool isn't empty.
- * @return
- */
- SMPManager::operator bool() noexcept { return !m_ThreadList.Empty(); }
-
- /**
- * Reverse operator bool
- * @return
- */
- bool SMPManager::operator!() noexcept { return m_ThreadList.Empty(); }
-} // namespace hCore
+ return false;
+}
+
+/**
+ * Index hart
+ * @param idx
+ * @return
+ */
+Ref<ProcessorCore> SMPManager::operator[](const SizeT& idx) {
+ return m_ThreadList[idx].Leak();
+}
+
+/**
+ * Check if thread pool isn't empty.
+ * @return
+ */
+SMPManager::operator bool() noexcept { return !m_ThreadList.Empty(); }
+
+/**
+ * Reverse operator bool
+ * @return
+ */
+bool SMPManager::operator!() noexcept { return m_ThreadList.Empty(); }
+} // namespace hCore