summaryrefslogtreecommitdiffhomepage
path: root/Kernel/KernelKit/ThreadLocalStorage.inl
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-09 00:42:44 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-09 00:42:44 +0200
commitaf8a516fc22865abd80d6e26f1541fa3d6bebfdc (patch)
tree96d42a10945fc03df022389aef54708383c1d616 /Kernel/KernelKit/ThreadLocalStorage.inl
parenta874e9cc98df994178d55996943fe81799c61d2f (diff)
MHR-23: :boom:, refactors.
- Move NewBoot to /Boot, thus making Kernel directory only containing the kernel. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/KernelKit/ThreadLocalStorage.inl')
-rw-r--r--Kernel/KernelKit/ThreadLocalStorage.inl55
1 files changed, 55 insertions, 0 deletions
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 <KernelKit/ProcessScheduler.hpp>
+#endif
+
+template <typename T>
+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 <typename T>
+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 <typename T, typename... Args>
+T* tls_new_class(Args&&... args)
+{
+ T* ptr = tls_new_ptr<T>();
+
+ if (ptr)
+ {
+ *ptr = T(NewOS::forward(args)...);
+ return ptr;
+ }
+
+ return nullptr;
+}