summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/kernel.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2021-01-21 22:00:16 +0100
committerbunnei <bunneidev@gmail.com>2021-01-29 06:42:26 +0100
commit6e953f7f0294d945ba9d6f08350d5dccb0d76075 (patch)
tree92a498827c4de7dd372731eff83c66aa3f57f060 /src/core/hle/kernel/kernel.cpp
parenthle: kernel: k_scheduler: Use atomics for current_thread, etc. (diff)
downloadyuzu-6e953f7f0294d945ba9d6f08350d5dccb0d76075.tar
yuzu-6e953f7f0294d945ba9d6f08350d5dccb0d76075.tar.gz
yuzu-6e953f7f0294d945ba9d6f08350d5dccb0d76075.tar.bz2
yuzu-6e953f7f0294d945ba9d6f08350d5dccb0d76075.tar.lz
yuzu-6e953f7f0294d945ba9d6f08350d5dccb0d76075.tar.xz
yuzu-6e953f7f0294d945ba9d6f08350d5dccb0d76075.tar.zst
yuzu-6e953f7f0294d945ba9d6f08350d5dccb0d76075.zip
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
-rw-r--r--src/core/hle/kernel/kernel.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 6142496b6..093886b7c 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -57,9 +57,10 @@ struct KernelCore::Impl {
}
void Initialize(KernelCore& kernel) {
+ global_scheduler_context = std::make_unique<Kernel::GlobalSchedulerContext>(kernel);
+
RegisterHostThread();
- global_scheduler_context = std::make_unique<Kernel::GlobalSchedulerContext>(kernel);
service_thread_manager =
std::make_unique<Common::ThreadWorker>(1, "yuzu:ServiceThreadManager");
is_phantom_mode_for_singlecore = false;
@@ -206,6 +207,18 @@ struct KernelCore::Impl {
return host_thread_id;
}
+ // Gets the dummy KThread for the caller, allocating a new one if this is the first time
+ KThread* GetHostDummyThread() {
+ const thread_local auto thread =
+ KThread::Create(
+ system, ThreadType::Main,
+ std::string{"DummyThread:" + GetHostThreadId()}, 0, KThread::DefaultThreadPriority,
+ 0, static_cast<u32>(3), 0, nullptr,
+ []([[maybe_unused]] void* arg) { UNREACHABLE(); }, nullptr)
+ .Unwrap();
+ return thread.get();
+ }
+
/// Registers a CPU core thread by allocating a host thread ID for it
void RegisterCoreThread(std::size_t core_id) {
ASSERT(core_id < Core::Hardware::NUM_CPU_CORES);
@@ -218,6 +231,7 @@ struct KernelCore::Impl {
/// Registers a new host thread by allocating a host thread ID for it
void RegisterHostThread() {
[[maybe_unused]] const auto this_id = GetHostThreadId();
+ [[maybe_unused]] const auto dummy_thread = GetHostDummyThread();
}
[[nodiscard]] u32 GetCurrentHostThreadID() {
@@ -237,13 +251,12 @@ struct KernelCore::Impl {
is_phantom_mode_for_singlecore = value;
}
- [[nodiscard]] EmuThreadHandle GetCurrentEmuThreadID() {
+ KThread* GetCurrentEmuThread() {
const auto thread_id = GetCurrentHostThreadID();
if (thread_id >= Core::Hardware::NUM_CPU_CORES) {
- // Reserved value for HLE threads
- return EmuThreadHandleReserved + (static_cast<u64>(thread_id) << 1);
+ return GetHostDummyThread();
}
- return reinterpret_cast<uintptr_t>(schedulers[thread_id].get());
+ return schedulers[thread_id]->GetCurrentThread();
}
void InitializeMemoryLayout() {
@@ -548,8 +561,8 @@ u32 KernelCore::GetCurrentHostThreadID() const {
return impl->GetCurrentHostThreadID();
}
-EmuThreadHandle KernelCore::GetCurrentEmuThreadID() const {
- return impl->GetCurrentEmuThreadID();
+KThread* KernelCore::GetCurrentEmuThread() const {
+ return impl->GetCurrentEmuThread();
}
Memory::MemoryManager& KernelCore::MemoryManager() {