diff options
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 8673384ee..8fdab44e4 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -261,20 +261,23 @@ struct KernelCore::Impl { | |||
| 261 | current_process = process; | 261 | current_process = process; |
| 262 | } | 262 | } |
| 263 | 263 | ||
| 264 | /// Creates a new host thread ID, should only be called by GetHostThreadId | 264 | static inline thread_local u32 host_thread_id = UINT32_MAX; |
| 265 | u32 AllocateHostThreadId(std::optional<std::size_t> core_id) { | 265 | |
| 266 | if (core_id) { | 266 | /// Gets the host thread ID for the caller, allocating a new one if this is the first time |
| 267 | // The first for slots are reserved for CPU core threads | 267 | u32 GetHostThreadId(std::size_t core_id) { |
| 268 | ASSERT(*core_id < Core::Hardware::NUM_CPU_CORES); | 268 | if (host_thread_id == UINT32_MAX) { |
| 269 | return static_cast<u32>(*core_id); | 269 | // The first four slots are reserved for CPU core threads |
| 270 | } else { | 270 | ASSERT(core_id < Core::Hardware::NUM_CPU_CORES); |
| 271 | return next_host_thread_id++; | 271 | host_thread_id = static_cast<u32>(core_id); |
| 272 | } | 272 | } |
| 273 | return host_thread_id; | ||
| 273 | } | 274 | } |
| 274 | 275 | ||
| 275 | /// Gets the host thread ID for the caller, allocating a new one if this is the first time | 276 | /// Gets the host thread ID for the caller, allocating a new one if this is the first time |
| 276 | u32 GetHostThreadId(std::optional<std::size_t> core_id = std::nullopt) { | 277 | u32 GetHostThreadId() { |
| 277 | const thread_local auto host_thread_id{AllocateHostThreadId(core_id)}; | 278 | if (host_thread_id == UINT32_MAX) { |
| 279 | host_thread_id = next_host_thread_id++; | ||
| 280 | } | ||
| 278 | return host_thread_id; | 281 | return host_thread_id; |
| 279 | } | 282 | } |
| 280 | 283 | ||