From eba8b7ddd0a455d9e49f32dcae712c5612c0093c Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 26 Jan 2024 22:26:48 +0100 Subject: Kernel: Major repository refactor. Rework the repo into Private and Public modules. Signed-off-by: Amlal El Mahrouss --- Private/KernelKit/ThreadLocalStorage.inl | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Private/KernelKit/ThreadLocalStorage.inl (limited to 'Private/KernelKit/ThreadLocalStorage.inl') diff --git a/Private/KernelKit/ThreadLocalStorage.inl b/Private/KernelKit/ThreadLocalStorage.inl new file mode 100644 index 00000000..bf557122 --- /dev/null +++ b/Private/KernelKit/ThreadLocalStorage.inl @@ -0,0 +1,50 @@ +/* + * ======================================================== + * + * hCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +//! @brief Allocates a pointer from the process's tls. + +template +inline T* hcore_tls_new_ptr(void) +{ + using namespace hCore; + + auto ref_process = ProcessManager::Shared().Leak().GetCurrent(); + + T* pointer = (T*)ref_process.Leak().New(sizeof(T)); + return pointer; +} + +//! @brief TLS delete implementation. +template +inline bool hcore_tls_delete_ptr(T* ptr) +{ + if (!ptr) + return false; + + using namespace hCore; + + auto ref_process = ProcessManager::Shared().Leak().GetCurrent(); + ptr->~T(); + + return ref_process.Leak().Delete(ptr, sizeof(T)); +} + +template +T* hcore_tls_new_class(Args&&... args) +{ + T* ptr = hcore_tls_new_ptr(); + + if (ptr) + { + *ptr = T(hCore::forward(args)...); + return ptr; + } + + return nullptr; +} -- cgit v1.2.3