summaryrefslogtreecommitdiffhomepage
path: root/Kernel/KernelKit/ThreadLocalStorage.inl
diff options
context:
space:
mode:
authorAmlal <amlalelmahrouss@icloud.com>2024-05-11 06:43:54 +0000
committerAmlal <amlalelmahrouss@icloud.com>2024-05-11 06:43:54 +0000
commitca675beb41dba8d7d16c5793b55d1672f38be3b4 (patch)
treec995ada42729ac2059a0ed87a4539d1a7e10b14a /Kernel/KernelKit/ThreadLocalStorage.inl
parent2b4a4792abf51487ab4a16106f9376f43acf381a (diff)
parentbc57a29a24b98b00ba17710ba84ec2188ab73504 (diff)
Merged in MHR-23 (pull request #12)
MHR-23: Merge work.
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;
+}