From af8a516fc22865abd80d6e26f1541fa3d6bebfdc Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 9 May 2024 00:42:44 +0200 Subject: MHR-23: :boom:, refactors. - Move NewBoot to /Boot, thus making Kernel directory only containing the kernel. Signed-off-by: Amlal El Mahrouss --- Kernel/KernelKit/ThreadLocalStorage.inl | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Kernel/KernelKit/ThreadLocalStorage.inl (limited to 'Kernel/KernelKit/ThreadLocalStorage.inl') diff --git a/Kernel/KernelKit/ThreadLocalStorage.inl b/Kernel/KernelKit/ThreadLocalStorage.inl new file mode 100644 index 00000000..ae3277eb --- /dev/null +++ b/Kernel/KernelKit/ThreadLocalStorage.inl @@ -0,0 +1,55 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +//! @brief Allocates a pointer from the process's tls. + +#ifndef __PROCESS_MANAGER__ +#include +#endif + +template +inline T* tls_new_ptr(void) +{ + using namespace NewOS; + + MUST_PASS(ProcessScheduler::Shared().Leak().GetCurrent()); + + auto ref_process = ProcessScheduler::Shared().Leak().GetCurrent(); + + T* pointer = (T*)ref_process.Leak().New(sizeof(T)); + return pointer; +} + +//! @brief TLS delete implementation. +template +inline bool tls_delete_ptr(T* ptr) +{ + if (!ptr) + return false; + + using namespace NewOS; + + MUST_PASS(ProcessScheduler::Shared().Leak().GetCurrent()); + + ptr->~T(); + + auto ref_process = ProcessScheduler::Shared().Leak().GetCurrent(); + return ref_process.Leak().Delete(ptr, sizeof(T)); +} + +template +T* tls_new_class(Args&&... args) +{ + T* ptr = tls_new_ptr(); + + if (ptr) + { + *ptr = T(NewOS::forward(args)...); + return ptr; + } + + return nullptr; +} -- cgit v1.2.3