summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/kernel.cpp
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2020-02-22 10:27:40 -0400
committerGravatar FernandoS272020-02-22 11:18:07 -0400
commitd219a96cc828d17932beebead209ba696b92a911 (patch)
tree1e973969f39a1901650626699117f93a4d731755 /src/core/hle/kernel/kernel.cpp
parentKernel: Implement Scheduler locks (diff)
downloadyuzu-d219a96cc828d17932beebead209ba696b92a911.tar.gz
yuzu-d219a96cc828d17932beebead209ba696b92a911.tar.xz
yuzu-d219a96cc828d17932beebead209ba696b92a911.zip
Kernel: Address Feedback.
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
-rw-r--r--src/core/hle/kernel/kernel.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index de14e1936..9232f4d7e 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -3,6 +3,7 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <atomic> 5#include <atomic>
6#include <bitset>
6#include <functional> 7#include <functional>
7#include <memory> 8#include <memory>
8#include <mutex> 9#include <mutex>
@@ -17,6 +18,7 @@
17#include "core/core.h" 18#include "core/core.h"
18#include "core/core_timing.h" 19#include "core/core_timing.h"
19#include "core/core_timing_util.h" 20#include "core/core_timing_util.h"
21#include "core/hardware_properties.h"
20#include "core/hle/kernel/client_port.h" 22#include "core/hle/kernel/client_port.h"
21#include "core/hle/kernel/errors.h" 23#include "core/hle/kernel/errors.h"
22#include "core/hle/kernel/handle_table.h" 24#include "core/hle/kernel/handle_table.h"
@@ -188,6 +190,7 @@ struct KernelCore::Impl {
188 } 190 }
189 191
190 void RegisterCoreThread(std::size_t core_id) { 192 void RegisterCoreThread(std::size_t core_id) {
193 std::unique_lock lock{register_thread_mutex};
191 const std::thread::id this_id = std::this_thread::get_id(); 194 const std::thread::id this_id = std::this_thread::get_id();
192 const auto it = host_thread_ids.find(this_id); 195 const auto it = host_thread_ids.find(this_id);
193 ASSERT(core_id < Core::Hardware::NUM_CPU_CORES); 196 ASSERT(core_id < Core::Hardware::NUM_CPU_CORES);
@@ -198,13 +201,14 @@ struct KernelCore::Impl {
198 } 201 }
199 202
200 void RegisterHostThread() { 203 void RegisterHostThread() {
204 std::unique_lock lock{register_thread_mutex};
201 const std::thread::id this_id = std::this_thread::get_id(); 205 const std::thread::id this_id = std::this_thread::get_id();
202 const auto it = host_thread_ids.find(this_id); 206 const auto it = host_thread_ids.find(this_id);
203 ASSERT(it == host_thread_ids.end()); 207 ASSERT(it == host_thread_ids.end());
204 host_thread_ids[this_id] = registered_thread_ids++; 208 host_thread_ids[this_id] = registered_thread_ids++;
205 } 209 }
206 210
207 u32 GetCurrentHostThreadId() const { 211 u32 GetCurrentHostThreadID() const {
208 const std::thread::id this_id = std::this_thread::get_id(); 212 const std::thread::id this_id = std::this_thread::get_id();
209 const auto it = host_thread_ids.find(this_id); 213 const auto it = host_thread_ids.find(this_id);
210 if (it == host_thread_ids.end()) { 214 if (it == host_thread_ids.end()) {
@@ -213,9 +217,9 @@ struct KernelCore::Impl {
213 return it->second; 217 return it->second;
214 } 218 }
215 219
216 Core::EmuThreadHandle GetCurrentEmuThreadId() const { 220 Core::EmuThreadHandle GetCurrentEmuThreadID() const {
217 Core::EmuThreadHandle result = Core::EmuThreadHandle::InvalidHandle(); 221 Core::EmuThreadHandle result = Core::EmuThreadHandle::InvalidHandle();
218 result.host_handle = GetCurrentHostThreadId(); 222 result.host_handle = GetCurrentHostThreadID();
219 if (result.host_handle >= Core::Hardware::NUM_CPU_CORES) { 223 if (result.host_handle >= Core::Hardware::NUM_CPU_CORES) {
220 return result; 224 return result;
221 } 225 }
@@ -246,8 +250,8 @@ struct KernelCore::Impl {
246 std::shared_ptr<Core::Timing::EventType> thread_wakeup_event_type; 250 std::shared_ptr<Core::Timing::EventType> thread_wakeup_event_type;
247 std::shared_ptr<Core::Timing::EventType> preemption_event; 251 std::shared_ptr<Core::Timing::EventType> preemption_event;
248 252
249 // TODO(yuriks): This can be removed if Thread objects are explicitly pooled in the future, 253 // This is the kernel's handle table or supervisor handle table which
250 // allowing us to simply use a pool index or similar. 254 // stores all the objects in place.
251 Kernel::HandleTable global_handle_table; 255 Kernel::HandleTable global_handle_table;
252 256
253 /// Map of named ports managed by the kernel, which can be retrieved using 257 /// Map of named ports managed by the kernel, which can be retrieved using
@@ -257,10 +261,11 @@ struct KernelCore::Impl {
257 std::unique_ptr<Core::ExclusiveMonitor> exclusive_monitor; 261 std::unique_ptr<Core::ExclusiveMonitor> exclusive_monitor;
258 std::vector<Kernel::PhysicalCore> cores; 262 std::vector<Kernel::PhysicalCore> cores;
259 263
260 // 0-3 Ids represent core threads, >3 represent others 264 // 0-3 IDs represent core threads, >3 represent others
261 std::unordered_map<std::thread::id, u32> host_thread_ids; 265 std::unordered_map<std::thread::id, u32> host_thread_ids;
262 u32 registered_thread_ids{Core::Hardware::NUM_CPU_CORES}; 266 u32 registered_thread_ids{Core::Hardware::NUM_CPU_CORES};
263 std::bitset<Core::Hardware::NUM_CPU_CORES> registered_core_threads{}; 267 std::bitset<Core::Hardware::NUM_CPU_CORES> registered_core_threads;
268 std::mutex register_thread_mutex;
264 269
265 // System context 270 // System context
266 Core::System& system; 271 Core::System& system;
@@ -420,12 +425,12 @@ void KernelCore::RegisterHostThread() {
420 impl->RegisterHostThread(); 425 impl->RegisterHostThread();
421} 426}
422 427
423u32 KernelCore::GetCurrentHostThreadId() const { 428u32 KernelCore::GetCurrentHostThreadID() const {
424 return impl->GetCurrentHostThreadId(); 429 return impl->GetCurrentHostThreadID();
425} 430}
426 431
427Core::EmuThreadHandle KernelCore::GetCurrentEmuThreadId() const { 432Core::EmuThreadHandle KernelCore::GetCurrentEmuThreadID() const {
428 return impl->GetCurrentEmuThreadId(); 433 return impl->GetCurrentEmuThreadID();
429} 434}
430 435
431} // namespace Kernel 436} // namespace Kernel