summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/KernelKit/HardwareThreadScheduler.h
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-04-25 13:08:33 +0200
committerAmlal <amlal@nekernel.org>2025-04-25 13:08:33 +0200
commitfb790b07aeba8e22e4190cf3e1834d11ecde6c96 (patch)
tree4cec7d1b321307b1d5935577631dae116a658a37 /dev/kernel/KernelKit/HardwareThreadScheduler.h
parent63a2d92c5dfe976175cda024ec01905d11b43738 (diff)
dev: better .clang-format, ran format command.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/KernelKit/HardwareThreadScheduler.h')
-rw-r--r--dev/kernel/KernelKit/HardwareThreadScheduler.h251
1 files changed, 119 insertions, 132 deletions
diff --git a/dev/kernel/KernelKit/HardwareThreadScheduler.h b/dev/kernel/KernelKit/HardwareThreadScheduler.h
index 4d2ebc73..4f7746ef 100644
--- a/dev/kernel/KernelKit/HardwareThreadScheduler.h
+++ b/dev/kernel/KernelKit/HardwareThreadScheduler.h
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
@@ -16,134 +16,121 @@
#define kMaxAPInsideSched (8U)
-namespace Kernel
-{
- class HardwareThread;
- class HardwareThreadScheduler;
-
- using ThreadID = UInt32;
-
- enum ThreadKind
- {
- kAPInvalid,
- kAPSystemReserved, // System reserved thread, well user can't use it
- kAPStandard, // user thread, cannot be used by Kernel
- kAPRealTime, // fallback thread, cannot be used by user if not clear or
- // used by Kernel.
- kAPBoot, // The core we booted from, the mama.
- kAPCount,
- };
-
- typedef enum ThreadKind ThreadKind;
- typedef ThreadID ThreadID;
-
- /***********************************************************************************/
- ///
- /// \name HardwareThread
- /// \brief Abstraction over the CPU's core, used to run processes or threads.
- ///
- /***********************************************************************************/
-
- class HardwareThread final
- {
- public:
- explicit HardwareThread();
- ~HardwareThread();
-
- public:
- NE_COPY_DEFAULT(HardwareThread)
-
- public:
- operator bool();
-
- public:
- void Wake(const BOOL wakeup = false) noexcept;
- void Busy(const BOOL busy = false) noexcept;
-
- public:
- BOOL Switch(VoidPtr image, Ptr8 stack_ptr, HAL::StackFramePtr frame, const ThreadID& pid);
- BOOL IsWakeup() noexcept;
-
- public:
- HAL::StackFramePtr StackFrame() noexcept;
- const ThreadKind& Kind() noexcept;
- bool IsBusy() noexcept;
- const ThreadID& ID() noexcept;
-
- private:
- HAL::StackFramePtr fStack{nullptr};
- ThreadKind fKind{ThreadKind::kAPStandard};
- ThreadID fID{0};
- ThreadID fPID{0};
- Bool fWakeup{NO};
- Bool fBusy{NO};
- UInt64 fPTime{0};
-
- private:
- friend class HardwareThreadScheduler;
- friend class UserProcessHelper;
- };
-
- ///
- /// \name HardwareThreadScheduler
- /// \brief Class to manage the thread scheduling.
- ///
-
- class HardwareThreadScheduler final : public ISchedulable
- {
- private:
- friend class UserProcessHelper;
-
- public:
- explicit HardwareThreadScheduler();
- ~HardwareThreadScheduler();
- NE_COPY_DEFAULT(HardwareThreadScheduler)
-
- public:
- HAL::StackFramePtr Leak() noexcept;
-
- public:
- Ref<HardwareThread*> operator[](SizeT idx);
- bool operator!() noexcept;
- operator bool() noexcept;
-
- Bool IsUser() override
- {
- return Yes;
- }
-
- Bool IsKernel() override
- {
- return No;
- }
-
- Bool HasMP() override
- {
- return kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled;
- }
-
- public:
- /// @brief Shared instance of the MP Mgr.
- /// @return the reference to the mp manager class.
- STATIC HardwareThreadScheduler& The();
-
- public:
- /// @brief Returns the amount of threads present in the system.
- /// @returns SizeT the amount of cores present.
- SizeT Capacity() noexcept;
-
- private:
- Array<HardwareThread, kMaxAPInsideSched> fThreadList;
- ThreadID fCurrentThread{0};
- };
-
- /// @brief wakes up thread.
- /// wakes up thread from hang.
- Void mp_wakeup_thread(HAL::StackFramePtr stack);
-
- /// @brief makes thread sleep.
- /// hooks and hangs thread to prevent code from executing.
- Void mp_hang_thread(HAL::StackFramePtr stack);
-} // namespace Kernel
-
-#endif // !__INC_MP_MANAGER_H__
+namespace Kernel {
+class HardwareThread;
+class HardwareThreadScheduler;
+
+using ThreadID = UInt32;
+
+enum ThreadKind {
+ kAPInvalid,
+ kAPSystemReserved, // System reserved thread, well user can't use it
+ kAPStandard, // user thread, cannot be used by Kernel
+ kAPRealTime, // fallback thread, cannot be used by user if not clear or
+ // used by Kernel.
+ kAPBoot, // The core we booted from, the mama.
+ kAPCount,
+};
+
+typedef enum ThreadKind ThreadKind;
+typedef ThreadID ThreadID;
+
+/***********************************************************************************/
+///
+/// \name HardwareThread
+/// \brief Abstraction over the CPU's core, used to run processes or threads.
+///
+/***********************************************************************************/
+
+class HardwareThread final {
+ public:
+ explicit HardwareThread();
+ ~HardwareThread();
+
+ public:
+ NE_COPY_DEFAULT(HardwareThread)
+
+ public:
+ operator bool();
+
+ public:
+ void Wake(const BOOL wakeup = false) noexcept;
+ void Busy(const BOOL busy = false) noexcept;
+
+ public:
+ BOOL Switch(VoidPtr image, Ptr8 stack_ptr, HAL::StackFramePtr frame, const ThreadID& pid);
+ BOOL IsWakeup() noexcept;
+
+ public:
+ HAL::StackFramePtr StackFrame() noexcept;
+ const ThreadKind& Kind() noexcept;
+ bool IsBusy() noexcept;
+ const ThreadID& ID() noexcept;
+
+ private:
+ HAL::StackFramePtr fStack{nullptr};
+ ThreadKind fKind{ThreadKind::kAPStandard};
+ ThreadID fID{0};
+ ThreadID fPID{0};
+ Bool fWakeup{NO};
+ Bool fBusy{NO};
+ UInt64 fPTime{0};
+
+ private:
+ friend class HardwareThreadScheduler;
+ friend class UserProcessHelper;
+};
+
+///
+/// \name HardwareThreadScheduler
+/// \brief Class to manage the thread scheduling.
+///
+
+class HardwareThreadScheduler final : public ISchedulable {
+ private:
+ friend class UserProcessHelper;
+
+ public:
+ explicit HardwareThreadScheduler();
+ ~HardwareThreadScheduler();
+ NE_COPY_DEFAULT(HardwareThreadScheduler)
+
+ public:
+ HAL::StackFramePtr Leak() noexcept;
+
+ public:
+ Ref<HardwareThread*> operator[](SizeT idx);
+ bool operator!() noexcept;
+ operator bool() noexcept;
+
+ Bool IsUser() override { return Yes; }
+
+ Bool IsKernel() override { return No; }
+
+ Bool HasMP() override { return kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled; }
+
+ public:
+ /// @brief Shared instance of the MP Mgr.
+ /// @return the reference to the mp manager class.
+ STATIC HardwareThreadScheduler& The();
+
+ public:
+ /// @brief Returns the amount of threads present in the system.
+ /// @returns SizeT the amount of cores present.
+ SizeT Capacity() noexcept;
+
+ private:
+ Array<HardwareThread, kMaxAPInsideSched> fThreadList;
+ ThreadID fCurrentThread{0};
+};
+
+/// @brief wakes up thread.
+/// wakes up thread from hang.
+Void mp_wakeup_thread(HAL::StackFramePtr stack);
+
+/// @brief makes thread sleep.
+/// hooks and hangs thread to prevent code from executing.
+Void mp_hang_thread(HAL::StackFramePtr stack);
+} // namespace Kernel
+
+#endif // !__INC_MP_MANAGER_H__