diff options
author | Ameer J <52414509+ameerj@users.noreply.github.com> | 2021-08-24 06:01:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-24 06:01:13 +0200 |
commit | bed0c3c92a6db45b29e787016fd21542606a031a (patch) | |
tree | d39b1dddcb578000b74c03a9e24564c9279f4411 /src/core/hle | |
parent | Merge pull request #6912 from lioncash/plural (diff) | |
parent | kernel: Optimize GetHostThreadID (diff) | |
download | yuzu-bed0c3c92a6db45b29e787016fd21542606a031a.tar yuzu-bed0c3c92a6db45b29e787016fd21542606a031a.tar.gz yuzu-bed0c3c92a6db45b29e787016fd21542606a031a.tar.bz2 yuzu-bed0c3c92a6db45b29e787016fd21542606a031a.tar.lz yuzu-bed0c3c92a6db45b29e787016fd21542606a031a.tar.xz yuzu-bed0c3c92a6db45b29e787016fd21542606a031a.tar.zst yuzu-bed0c3c92a6db45b29e787016fd21542606a031a.zip |
Diffstat (limited to 'src/core/hle')
-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 { current_process = process; } - /// Creates a new host thread ID, should only be called by GetHostThreadId - u32 AllocateHostThreadId(std::optional<std::size_t> core_id) { - if (core_id) { - // The first for slots are reserved for CPU core threads - ASSERT(*core_id < Core::Hardware::NUM_CPU_CORES); - return static_cast<u32>(*core_id); - } else { - return next_host_thread_id++; + static inline thread_local u32 host_thread_id = UINT32_MAX; + + /// Gets the host thread ID for the caller, allocating a new one if this is the first time + u32 GetHostThreadId(std::size_t core_id) { + if (host_thread_id == UINT32_MAX) { + // The first four slots are reserved for CPU core threads + ASSERT(core_id < Core::Hardware::NUM_CPU_CORES); + host_thread_id = static_cast<u32>(core_id); } + return host_thread_id; } /// Gets the host thread ID for the caller, allocating a new one if this is the first time - u32 GetHostThreadId(std::optional<std::size_t> core_id = std::nullopt) { - const thread_local auto host_thread_id{AllocateHostThreadId(core_id)}; + u32 GetHostThreadId() { + if (host_thread_id == UINT32_MAX) { + host_thread_id = next_host_thread_id++; + } return host_thread_id; } |