| 1 | #ifndef SEAD_THREAD_THREAD_LOCAL_STORAGE_H_ |
|---|---|
| 2 | #include "thread/seadThreadLocalStorage.h" |
| 3 | #endif |
| 4 | |
| 5 | #include "basis/seadRawPrint.h" |
| 6 | |
| 7 | namespace sead |
| 8 | { |
| 9 | inline ThreadLocalStorage::ThreadLocalStorage() |
| 10 | { |
| 11 | [[maybe_unused]] auto result = nn::os::AllocateTlsSlot(slot_out: &mTlsSlot, nullptr); |
| 12 | SEAD_ASSERT(result.IsSuccess()); |
| 13 | } |
| 14 | |
| 15 | inline ThreadLocalStorage::~ThreadLocalStorage() |
| 16 | { |
| 17 | nn::os::FreeTlsSlot(slot: mTlsSlot); |
| 18 | } |
| 19 | |
| 20 | inline void ThreadLocalStorage::setValue(uintptr_t value) |
| 21 | { |
| 22 | static_assert(sizeof(uintptr_t) == sizeof(u64), "uintptr_t and u64 should have the same size"); |
| 23 | nn::os::SetTlsValue(slot: mTlsSlot, value); |
| 24 | } |
| 25 | |
| 26 | inline uintptr_t ThreadLocalStorage::getValue() const |
| 27 | { |
| 28 | return nn::os::GetTlsValue(slot: mTlsSlot); |
| 29 | } |
| 30 | } // namespace sead |
| 31 |