diff options
| author | Amlal <amlal.elmahrouss@icloud.com> | 2024-10-28 07:01:58 +0100 |
|---|---|---|
| committer | Amlal <amlal.elmahrouss@icloud.com> | 2024-10-28 07:01:58 +0100 |
| commit | e0024d9ea688ee91a77abc0e28c5ea24b13ca67d (patch) | |
| tree | a4e29bd919cbeccf2689e81a5d52bfc02f2a8b77 /dev/ZKAKit/KernelKit/ThreadLocalStorage.inl | |
| parent | 36a3600ff7fc65a63b7386b7a680dbe8e647bd8f (diff) | |
IMP: Refactor whole source code to make it even.
- That is because previously the source was both in lowercase and lettercase.
Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKAKit/KernelKit/ThreadLocalStorage.inl')
| -rw-r--r-- | dev/ZKAKit/KernelKit/ThreadLocalStorage.inl | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/dev/ZKAKit/KernelKit/ThreadLocalStorage.inl b/dev/ZKAKit/KernelKit/ThreadLocalStorage.inl new file mode 100644 index 00000000..305d3966 --- /dev/null +++ b/dev/ZKAKit/KernelKit/ThreadLocalStorage.inl @@ -0,0 +1,74 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +//! @file ThreadLocalStorage.inl +//! @brief Allocate resources from the process's heap storage. + +#ifndef INC_PROCESS_SCHEDULER_HXX +#include <KernelKit/UserProcessScheduler.h> +#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); +} |
