diff options
| author | 2021-08-15 15:30:56 -0500 | |
|---|---|---|
| committer | 2021-08-16 07:30:23 -0500 | |
| commit | 14e93f133a8dc7b7aa0d0bb079d8b6ee495d922e (patch) | |
| tree | d805fce6b3137c6b76c2d08001a3abded0cf17d0 /src/core/hle/kernel/kernel.cpp | |
| parent | Merge pull request #6861 from yzct12345/const-mempy-is-all-the-speed (diff) | |
| download | yuzu-14e93f133a8dc7b7aa0d0bb079d8b6ee495d922e.tar.gz yuzu-14e93f133a8dc7b7aa0d0bb079d8b6ee495d922e.tar.xz yuzu-14e93f133a8dc7b7aa0d0bb079d8b6ee495d922e.zip | |
kernel: Optimize GetHostThreadID
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 92fbc5532..bea945301 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -267,20 +267,23 @@ struct KernelCore::Impl { | |||
| 267 | } | 267 | } |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | /// Creates a new host thread ID, should only be called by GetHostThreadId | 270 | static inline thread_local u32 host_thread_id = UINT32_MAX; |
| 271 | u32 AllocateHostThreadId(std::optional<std::size_t> core_id) { | 271 | |
| 272 | if (core_id) { | 272 | /// Gets the host thread ID for the caller, allocating a new one if this is the first time |
| 273 | // The first for slots are reserved for CPU core threads | 273 | u32 GetHostThreadId(std::size_t core_id) { |
| 274 | ASSERT(*core_id < Core::Hardware::NUM_CPU_CORES); | 274 | if (host_thread_id == UINT32_MAX) { |
| 275 | return static_cast<u32>(*core_id); | 275 | // The first four slots are reserved for CPU core threads |
| 276 | } else { | 276 | ASSERT(core_id < Core::Hardware::NUM_CPU_CORES); |
| 277 | return next_host_thread_id++; | 277 | host_thread_id = static_cast<u32>(core_id); |
| 278 | } | 278 | } |
| 279 | return host_thread_id; | ||
| 279 | } | 280 | } |
| 280 | 281 | ||
| 281 | /// Gets the host thread ID for the caller, allocating a new one if this is the first time | 282 | /// Gets the host thread ID for the caller, allocating a new one if this is the first time |
| 282 | u32 GetHostThreadId(std::optional<std::size_t> core_id = std::nullopt) { | 283 | u32 GetHostThreadId() { |
| 283 | const thread_local auto host_thread_id{AllocateHostThreadId(core_id)}; | 284 | if (host_thread_id == UINT32_MAX) { |
| 285 | host_thread_id = next_host_thread_id++; | ||
| 286 | } | ||
| 284 | return host_thread_id; | 287 | return host_thread_id; |
| 285 | } | 288 | } |
| 286 | 289 | ||