summaryrefslogtreecommitdiffhomepage
path: root/dev/zka/KernelKit/ThreadLocalStorage.inl
diff options
context:
space:
mode:
authorAmlal <amlal@el-mahrouss-logic.com>2024-09-22 17:46:11 +0200
committerAmlal <amlal@el-mahrouss-logic.com>2024-09-22 17:46:11 +0200
commit8719b4570a2d10dd49a0d3a47e24f5c55bdda85e (patch)
treeba095740888f3768e08b2ea058b0ea6da2d0403d /dev/zka/KernelKit/ThreadLocalStorage.inl
parent45944b3d2dab04b763fcc6d10164fe8069e60b08 (diff)
:boom: A big refactor on the filesystem structure.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev/zka/KernelKit/ThreadLocalStorage.inl')
-rw-r--r--dev/zka/KernelKit/ThreadLocalStorage.inl74
1 files changed, 74 insertions, 0 deletions
diff --git a/dev/zka/KernelKit/ThreadLocalStorage.inl b/dev/zka/KernelKit/ThreadLocalStorage.inl
new file mode 100644
index 00000000..7a1ef247
--- /dev/null
+++ b/dev/zka/KernelKit/ThreadLocalStorage.inl
@@ -0,0 +1,74 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+//! @file ThreadLocalStorage.inl
+//! @brief Allocate resources from the process's heap storage.
+
+#ifndef _INC_PROCESS_SCHEDULER_HXX_
+#include <KernelKit/UserProcessScheduler.hxx>
+#endif
+
+template <typename T>
+inline T* tls_new_ptr(void) noexcept
+{
+ using namespace Kernel;
+
+ auto ref_process = UserProcessScheduler::The().CurrentProcess();
+ MUST_PASS(ref_process);
+
+ T* pointer = (T*)ref_process.Leak().New(sizeof(T));
+ return pointer;
+}
+
+//! @brief TLS delete implementation.
+template <typename T>
+inline Kernel::Bool tls_delete_ptr(T* ptr) noexcept
+{
+ if (!ptr)
+ return false;
+
+ using namespace Kernel;
+
+ auto ref_process = UserProcessScheduler::The().CurrentProcess();
+ MUST_PASS(ref_process);
+
+ return ref_process.Leak().Delete(ptr, sizeof(T));
+}
+
+/// @brief Allocate a C++ class, and then call the constructor of it.
+/// @tparam T
+/// @tparam ...Args
+/// @param ...args
+/// @return
+template <typename T, typename... Args>
+T* tls_new_class(Args&&... args)
+{
+ T* ptr = tls_new_ptr<T>();
+
+ using namespace Kernel;
+
+ if (ptr)
+ {
+ *ptr = T(forward(args)...);
+ return ptr;
+ }
+
+ return nullptr;
+}
+
+/// @brief Delete a C++ class (call constructor first.)
+/// @tparam T
+/// @param ptr
+/// @return
+template <typename T>
+inline Kernel::Bool tls_delete_class(T* ptr)
+{
+ if (!ptr)
+ return false;
+
+ ptr->~T();
+ return tls_delete_ptr(ptr);
+}