|
@@ -10,6 +10,7 @@
|
|
|
#include "common/assert.h"
|
|
#include "common/assert.h"
|
|
|
#include "common/spin_lock.h"
|
|
#include "common/spin_lock.h"
|
|
|
#include "core/hardware_properties.h"
|
|
#include "core/hardware_properties.h"
|
|
|
|
|
+#include "core/hle/kernel/k_thread.h"
|
|
|
#include "core/hle/kernel/kernel.h"
|
|
#include "core/hle/kernel/kernel.h"
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
namespace Kernel {
|
|
@@ -22,42 +23,42 @@ public:
|
|
|
explicit KAbstractSchedulerLock(KernelCore& kernel_) : kernel{kernel_} {}
|
|
explicit KAbstractSchedulerLock(KernelCore& kernel_) : kernel{kernel_} {}
|
|
|
|
|
|
|
|
bool IsLockedByCurrentThread() const {
|
|
bool IsLockedByCurrentThread() const {
|
|
|
- return this->owner_thread == kernel.GetCurrentEmuThreadID();
|
|
|
|
|
|
|
+ return this->owner_thread == GetCurrentThreadPointer(kernel);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Lock() {
|
|
void Lock() {
|
|
|
if (this->IsLockedByCurrentThread()) {
|
|
if (this->IsLockedByCurrentThread()) {
|
|
|
// If we already own the lock, we can just increment the count.
|
|
// If we already own the lock, we can just increment the count.
|
|
|
- ASSERT(this->lock_count > 0);
|
|
|
|
|
- this->lock_count++;
|
|
|
|
|
|
|
+ ASSERT(lock_count > 0);
|
|
|
|
|
+ lock_count++;
|
|
|
} else {
|
|
} else {
|
|
|
// Otherwise, we want to disable scheduling and acquire the spinlock.
|
|
// Otherwise, we want to disable scheduling and acquire the spinlock.
|
|
|
SchedulerType::DisableScheduling(kernel);
|
|
SchedulerType::DisableScheduling(kernel);
|
|
|
- this->spin_lock.lock();
|
|
|
|
|
|
|
+ spin_lock.lock();
|
|
|
|
|
|
|
|
// For debug, ensure that our state is valid.
|
|
// For debug, ensure that our state is valid.
|
|
|
- ASSERT(this->lock_count == 0);
|
|
|
|
|
- ASSERT(this->owner_thread == EmuThreadHandleInvalid);
|
|
|
|
|
|
|
+ ASSERT(lock_count == 0);
|
|
|
|
|
+ ASSERT(owner_thread == nullptr);
|
|
|
|
|
|
|
|
// Increment count, take ownership.
|
|
// Increment count, take ownership.
|
|
|
- this->lock_count = 1;
|
|
|
|
|
- this->owner_thread = kernel.GetCurrentEmuThreadID();
|
|
|
|
|
|
|
+ lock_count = 1;
|
|
|
|
|
+ owner_thread = GetCurrentThreadPointer(kernel);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Unlock() {
|
|
void Unlock() {
|
|
|
ASSERT(this->IsLockedByCurrentThread());
|
|
ASSERT(this->IsLockedByCurrentThread());
|
|
|
- ASSERT(this->lock_count > 0);
|
|
|
|
|
|
|
+ ASSERT(lock_count > 0);
|
|
|
|
|
|
|
|
// Release an instance of the lock.
|
|
// Release an instance of the lock.
|
|
|
- if ((--this->lock_count) == 0) {
|
|
|
|
|
|
|
+ if ((--lock_count) == 0) {
|
|
|
// We're no longer going to hold the lock. Take note of what cores need scheduling.
|
|
// We're no longer going to hold the lock. Take note of what cores need scheduling.
|
|
|
const u64 cores_needing_scheduling =
|
|
const u64 cores_needing_scheduling =
|
|
|
SchedulerType::UpdateHighestPriorityThreads(kernel);
|
|
SchedulerType::UpdateHighestPriorityThreads(kernel);
|
|
|
|
|
|
|
|
// Note that we no longer hold the lock, and unlock the spinlock.
|
|
// Note that we no longer hold the lock, and unlock the spinlock.
|
|
|
- this->owner_thread = EmuThreadHandleInvalid;
|
|
|
|
|
- this->spin_lock.unlock();
|
|
|
|
|
|
|
+ owner_thread = nullptr;
|
|
|
|
|
+ spin_lock.unlock();
|
|
|
|
|
|
|
|
// Enable scheduling, and perform a rescheduling operation.
|
|
// Enable scheduling, and perform a rescheduling operation.
|
|
|
SchedulerType::EnableScheduling(kernel, cores_needing_scheduling);
|
|
SchedulerType::EnableScheduling(kernel, cores_needing_scheduling);
|
|
@@ -68,7 +69,7 @@ private:
|
|
|
KernelCore& kernel;
|
|
KernelCore& kernel;
|
|
|
Common::SpinLock spin_lock{};
|
|
Common::SpinLock spin_lock{};
|
|
|
s32 lock_count{};
|
|
s32 lock_count{};
|
|
|
- EmuThreadHandle owner_thread{EmuThreadHandleInvalid};
|
|
|
|
|
|
|
+ KThread* owner_thread{};
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
} // namespace Kernel
|
|
} // namespace Kernel
|