summaryrefslogtreecommitdiffhomepage
path: root/KernelKit/ThreadLocalStorage.inl
blob: bf55712212b0d3b7642cfb82d18a28ff49544678 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 *	========================================================
 *
 *	hCore
 * 	Copyright 2024 Mahrouss Logic, all rights reserved.
 *
 * 	========================================================
 */

//! @brief Allocates a pointer from the process's tls.

template <typename T>
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 <typename T>
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 <typename T, typename... Args>
T* hcore_tls_new_class(Args&&... args)
{
    T* ptr = hcore_tls_new_ptr<T>();

    if (ptr)
    {
            *ptr = T(hCore::forward(args)...);
            return ptr;
    }

    return nullptr;
}