diff options
Diffstat (limited to 'src/core/hle/kernel/thread.cpp')
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 93ea58a1e..8af84d8cc 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -252,13 +252,14 @@ void Thread::ResumeFromWait() { | |||
| 252 | * slot: The index of the first free slot in the indicated page. | 252 | * slot: The index of the first free slot in the indicated page. |
| 253 | * alloc_needed: Whether there's a need to allocate a new TLS page (All pages are full). | 253 | * alloc_needed: Whether there's a need to allocate a new TLS page (All pages are full). |
| 254 | */ | 254 | */ |
| 255 | std::tuple<u32, u32, bool> GetFreeThreadLocalSlot(std::vector<std::bitset<8>>& tls_slots) { | 255 | static std::tuple<std::size_t, std::size_t, bool> GetFreeThreadLocalSlot( |
| 256 | const std::vector<std::bitset<8>>& tls_slots) { | ||
| 256 | // Iterate over all the allocated pages, and try to find one where not all slots are used. | 257 | // Iterate over all the allocated pages, and try to find one where not all slots are used. |
| 257 | for (unsigned page = 0; page < tls_slots.size(); ++page) { | 258 | for (std::size_t page = 0; page < tls_slots.size(); ++page) { |
| 258 | const auto& page_tls_slots = tls_slots[page]; | 259 | const auto& page_tls_slots = tls_slots[page]; |
| 259 | if (!page_tls_slots.all()) { | 260 | if (!page_tls_slots.all()) { |
| 260 | // We found a page with at least one free slot, find which slot it is | 261 | // We found a page with at least one free slot, find which slot it is |
| 261 | for (unsigned slot = 0; slot < page_tls_slots.size(); ++slot) { | 262 | for (std::size_t slot = 0; slot < page_tls_slots.size(); ++slot) { |
| 262 | if (!page_tls_slots.test(slot)) { | 263 | if (!page_tls_slots.test(slot)) { |
| 263 | return std::make_tuple(page, slot, false); | 264 | return std::make_tuple(page, slot, false); |
| 264 | } | 265 | } |
| @@ -333,11 +334,8 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, | |||
| 333 | 334 | ||
| 334 | // Find the next available TLS index, and mark it as used | 335 | // Find the next available TLS index, and mark it as used |
| 335 | auto& tls_slots = owner_process->tls_slots; | 336 | auto& tls_slots = owner_process->tls_slots; |
| 336 | bool needs_allocation = true; | ||
| 337 | u32 available_page; // Which allocated page has free space | ||
| 338 | u32 available_slot; // Which slot within the page is free | ||
| 339 | 337 | ||
| 340 | std::tie(available_page, available_slot, needs_allocation) = GetFreeThreadLocalSlot(tls_slots); | 338 | auto [available_page, available_slot, needs_allocation] = GetFreeThreadLocalSlot(tls_slots); |
| 341 | 339 | ||
| 342 | if (needs_allocation) { | 340 | if (needs_allocation) { |
| 343 | // There are no already-allocated pages with free slots, lets allocate a new one. | 341 | // There are no already-allocated pages with free slots, lets allocate a new one. |
| @@ -359,7 +357,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, | |||
| 359 | owner_process->linear_heap_used += Memory::PAGE_SIZE; | 357 | owner_process->linear_heap_used += Memory::PAGE_SIZE; |
| 360 | 358 | ||
| 361 | tls_slots.emplace_back(0); // The page is completely available at the start | 359 | tls_slots.emplace_back(0); // The page is completely available at the start |
| 362 | available_page = static_cast<u32>(tls_slots.size() - 1); | 360 | available_page = tls_slots.size() - 1; |
| 363 | available_slot = 0; // Use the first slot in the new page | 361 | available_slot = 0; // Use the first slot in the new page |
| 364 | 362 | ||
| 365 | auto& vm_manager = owner_process->vm_manager; | 363 | auto& vm_manager = owner_process->vm_manager; |