summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2021-01-20 06:07:07 +0100
committerbunnei <bunneidev@gmail.com>2021-01-29 06:42:26 +0100
commit1f99f5473c7a03c791ea20256c7fc2f1caba8adc (patch)
tree3dea03c0082e6685aeda2769fd7b186f0afbf46c /src/core/hle/kernel
parenthle: kernel: TimeManager: Simplify to not rely on previous EmuThreadHandle implementation. (diff)
downloadyuzu-1f99f5473c7a03c791ea20256c7fc2f1caba8adc.tar
yuzu-1f99f5473c7a03c791ea20256c7fc2f1caba8adc.tar.gz
yuzu-1f99f5473c7a03c791ea20256c7fc2f1caba8adc.tar.bz2
yuzu-1f99f5473c7a03c791ea20256c7fc2f1caba8adc.tar.lz
yuzu-1f99f5473c7a03c791ea20256c7fc2f1caba8adc.tar.xz
yuzu-1f99f5473c7a03c791ea20256c7fc2f1caba8adc.tar.zst
yuzu-1f99f5473c7a03c791ea20256c7fc2f1caba8adc.zip
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/k_light_lock.cpp12
-rw-r--r--src/core/hle/kernel/k_scheduler_lock.h9
-rw-r--r--src/core/hle/kernel/kernel.cpp21
-rw-r--r--src/core/hle/kernel/kernel.h6
4 files changed, 25 insertions, 23 deletions
diff --git a/src/core/hle/kernel/k_light_lock.cpp b/src/core/hle/kernel/k_light_lock.cpp
index 08fa65fd5..1d54ba5df 100644
--- a/src/core/hle/kernel/k_light_lock.cpp
+++ b/src/core/hle/kernel/k_light_lock.cpp
@@ -9,6 +9,12 @@
namespace Kernel {
+static KThread* ToThread(uintptr_t thread_) {
+ ASSERT((thread_ & EmuThreadHandleReserved) == 0);
+ ASSERT((thread_ & 1) == 0);
+ return reinterpret_cast<KThread*>(thread_);
+}
+
void KLightLock::Lock() {
const uintptr_t cur_thread = reinterpret_cast<uintptr_t>(GetCurrentThreadPointer(kernel));
const uintptr_t cur_thread_tag = (cur_thread | 1);
@@ -42,7 +48,7 @@ void KLightLock::Unlock() {
}
void KLightLock::LockSlowPath(uintptr_t _owner, uintptr_t _cur_thread) {
- KThread* cur_thread = reinterpret_cast<KThread*>(_cur_thread);
+ KThread* cur_thread = ToThread(_cur_thread);
// Pend the current thread waiting on the owner thread.
{
@@ -54,7 +60,7 @@ void KLightLock::LockSlowPath(uintptr_t _owner, uintptr_t _cur_thread) {
}
// Add the current thread as a waiter on the owner.
- KThread* owner_thread = reinterpret_cast<KThread*>(_owner & ~1ul);
+ KThread* owner_thread = ToThread(_owner & ~1ul);
cur_thread->SetAddressKey(reinterpret_cast<uintptr_t>(std::addressof(tag)));
owner_thread->AddWaiter(cur_thread);
@@ -82,7 +88,7 @@ void KLightLock::LockSlowPath(uintptr_t _owner, uintptr_t _cur_thread) {
}
void KLightLock::UnlockSlowPath(uintptr_t _cur_thread) {
- KThread* owner_thread = reinterpret_cast<KThread*>(_cur_thread);
+ KThread* owner_thread = ToThread(_cur_thread);
// Unlock.
{
diff --git a/src/core/hle/kernel/k_scheduler_lock.h b/src/core/hle/kernel/k_scheduler_lock.h
index 9b40bd22c..5d48dcf38 100644
--- a/src/core/hle/kernel/k_scheduler_lock.h
+++ b/src/core/hle/kernel/k_scheduler_lock.h
@@ -37,7 +37,7 @@ public:
// For debug, ensure that our state is valid.
ASSERT(this->lock_count == 0);
- ASSERT(this->owner_thread == Core::EmuThreadHandle::InvalidHandle());
+ ASSERT(this->owner_thread == EmuThreadHandleInvalid);
// Increment count, take ownership.
this->lock_count = 1;
@@ -54,14 +54,13 @@ public:
// We're no longer going to hold the lock. Take note of what cores need scheduling.
const u64 cores_needing_scheduling =
SchedulerType::UpdateHighestPriorityThreads(kernel);
- Core::EmuThreadHandle leaving_thread = owner_thread;
// Note that we no longer hold the lock, and unlock the spinlock.
- this->owner_thread = Core::EmuThreadHandle::InvalidHandle();
+ this->owner_thread = EmuThreadHandleInvalid;
this->spin_lock.unlock();
// Enable scheduling, and perform a rescheduling operation.
- SchedulerType::EnableScheduling(kernel, cores_needing_scheduling, leaving_thread);
+ SchedulerType::EnableScheduling(kernel, cores_needing_scheduling);
}
}
@@ -69,7 +68,7 @@ private:
KernelCore& kernel;
Common::SpinLock spin_lock{};
s32 lock_count{};
- Core::EmuThreadHandle owner_thread{Core::EmuThreadHandle::InvalidHandle()};
+ EmuThreadHandle owner_thread{EmuThreadHandleInvalid};
};
} // namespace Kernel
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 97a5dc2e0..39d5122f5 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -237,20 +237,13 @@ struct KernelCore::Impl {
is_phantom_mode_for_singlecore = value;
}
- [[nodiscard]] Core::EmuThreadHandle GetCurrentEmuThreadID() {
- Core::EmuThreadHandle result = Core::EmuThreadHandle::InvalidHandle();
- result.host_handle = GetCurrentHostThreadID();
- if (result.host_handle >= Core::Hardware::NUM_CPU_CORES) {
- return result;
+ [[nodiscard]] EmuThreadHandle GetCurrentEmuThreadID() {
+ 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);
}
- const Kernel::KScheduler& sched = cores[result.host_handle].Scheduler();
- const Kernel::KThread* current = sched.GetCurrentThread();
- if (current != nullptr && !IsPhantomModeForSingleCore()) {
- result.guest_handle = current->GetGlobalHandle();
- } else {
- result.guest_handle = InvalidHandle;
- }
- return result;
+ return reinterpret_cast<uintptr_t>(schedulers[thread_id].get());
}
void InitializeMemoryLayout() {
@@ -555,7 +548,7 @@ u32 KernelCore::GetCurrentHostThreadID() const {
return impl->GetCurrentHostThreadID();
}
-Core::EmuThreadHandle KernelCore::GetCurrentEmuThreadID() const {
+EmuThreadHandle KernelCore::GetCurrentEmuThreadID() const {
return impl->GetCurrentEmuThreadID();
}
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index fc58f3ecb..b92c017f6 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -46,6 +46,10 @@ class Synchronization;
class KThread;
class TimeManager;
+using EmuThreadHandle = uintptr_t;
+constexpr EmuThreadHandle EmuThreadHandleInvalid{};
+constexpr EmuThreadHandle EmuThreadHandleReserved{1ULL << 63};
+
/// Represents a single instance of the kernel.
class KernelCore {
private:
@@ -162,7 +166,7 @@ public:
bool IsValidNamedPort(NamedPortTable::const_iterator port) const;
/// Gets the current host_thread/guest_thread handle.
- Core::EmuThreadHandle GetCurrentEmuThreadID() const;
+ EmuThreadHandle GetCurrentEmuThreadID() const;
/// Gets the current host_thread handle.
u32 GetCurrentHostThreadID() const;