summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/kernel.cpp
diff options
context:
space:
mode:
authorGravatar Ameer J2021-08-24 00:01:13 -0400
committerGravatar GitHub2021-08-24 00:01:13 -0400
commitbed0c3c92a6db45b29e787016fd21542606a031a (patch)
treed39b1dddcb578000b74c03a9e24564c9279f4411 /src/core/hle/kernel/kernel.cpp
parentMerge pull request #6912 from lioncash/plural (diff)
parentkernel: Optimize GetHostThreadID (diff)
downloadyuzu-bed0c3c92a6db45b29e787016fd21542606a031a.tar.gz
yuzu-bed0c3c92a6db45b29e787016fd21542606a031a.tar.xz
yuzu-bed0c3c92a6db45b29e787016fd21542606a031a.zip
Merge pull request #6878 from BreadFish64/optimize-GetHostThreadID
kernel: Optimize GetHostThreadID
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
-rw-r--r--src/core/hle/kernel/kernel.cpp23
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