From 5339d016c07bf717ee388f4feb73544087324af0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 6 Jan 2024 09:14:11 +0100 Subject: git: port from mercurial repo. Signed-off-by: Amlal El Mahrouss --- KernelKit/ThreadLocalStorage.inl | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 KernelKit/ThreadLocalStorage.inl (limited to 'KernelKit/ThreadLocalStorage.inl') diff --git a/KernelKit/ThreadLocalStorage.inl b/KernelKit/ThreadLocalStorage.inl new file mode 100644 index 00000000..c117dd4e --- /dev/null +++ b/KernelKit/ThreadLocalStorage.inl @@ -0,0 +1,50 @@ +/* + * ======================================================== + * + * hCore + * Copyright 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