forked from suyu/suyu
hle: kernel: KThread: Remove tracking of sync object from threads.
This commit is contained in:
parent
bc1399204b
commit
2f89456041
6 changed files with 21 additions and 41 deletions
|
@ -97,7 +97,7 @@ ResultCode KAddressArbiter::Signal(VAddr addr, s32 count) {
|
||||||
while ((it != thread_tree.end()) && (count <= 0 || num_waiters < count) &&
|
while ((it != thread_tree.end()) && (count <= 0 || num_waiters < count) &&
|
||||||
(it->GetAddressArbiterKey() == addr)) {
|
(it->GetAddressArbiterKey() == addr)) {
|
||||||
KThread* target_thread = std::addressof(*it);
|
KThread* target_thread = std::addressof(*it);
|
||||||
target_thread->SetSyncedObject(nullptr, ResultSuccess);
|
target_thread->SetWaitResult(ResultSuccess);
|
||||||
|
|
||||||
ASSERT(target_thread->IsWaitingForAddressArbiter());
|
ASSERT(target_thread->IsWaitingForAddressArbiter());
|
||||||
target_thread->Wakeup();
|
target_thread->Wakeup();
|
||||||
|
@ -130,7 +130,7 @@ ResultCode KAddressArbiter::SignalAndIncrementIfEqual(VAddr addr, s32 value, s32
|
||||||
while ((it != thread_tree.end()) && (count <= 0 || num_waiters < count) &&
|
while ((it != thread_tree.end()) && (count <= 0 || num_waiters < count) &&
|
||||||
(it->GetAddressArbiterKey() == addr)) {
|
(it->GetAddressArbiterKey() == addr)) {
|
||||||
KThread* target_thread = std::addressof(*it);
|
KThread* target_thread = std::addressof(*it);
|
||||||
target_thread->SetSyncedObject(nullptr, ResultSuccess);
|
target_thread->SetWaitResult(ResultSuccess);
|
||||||
|
|
||||||
ASSERT(target_thread->IsWaitingForAddressArbiter());
|
ASSERT(target_thread->IsWaitingForAddressArbiter());
|
||||||
target_thread->Wakeup();
|
target_thread->Wakeup();
|
||||||
|
@ -198,7 +198,7 @@ ResultCode KAddressArbiter::SignalAndModifyByWaitingCountIfEqual(VAddr addr, s32
|
||||||
while ((it != thread_tree.end()) && (count <= 0 || num_waiters < count) &&
|
while ((it != thread_tree.end()) && (count <= 0 || num_waiters < count) &&
|
||||||
(it->GetAddressArbiterKey() == addr)) {
|
(it->GetAddressArbiterKey() == addr)) {
|
||||||
KThread* target_thread = std::addressof(*it);
|
KThread* target_thread = std::addressof(*it);
|
||||||
target_thread->SetSyncedObject(nullptr, ResultSuccess);
|
target_thread->SetWaitResult(ResultSuccess);
|
||||||
|
|
||||||
ASSERT(target_thread->IsWaitingForAddressArbiter());
|
ASSERT(target_thread->IsWaitingForAddressArbiter());
|
||||||
target_thread->Wakeup();
|
target_thread->Wakeup();
|
||||||
|
@ -225,7 +225,7 @@ ResultCode KAddressArbiter::WaitIfLessThan(VAddr addr, s32 value, bool decrement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the synced object.
|
// Set the synced object.
|
||||||
cur_thread->SetSyncedObject(nullptr, ResultTimedOut);
|
cur_thread->SetWaitResult(ResultTimedOut);
|
||||||
|
|
||||||
// Read the value from userspace.
|
// Read the value from userspace.
|
||||||
s32 user_value{};
|
s32 user_value{};
|
||||||
|
@ -274,8 +274,7 @@ ResultCode KAddressArbiter::WaitIfLessThan(VAddr addr, s32 value, bool decrement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the result.
|
// Get the result.
|
||||||
KSynchronizationObject* dummy{};
|
return cur_thread->GetWaitResult();
|
||||||
return cur_thread->GetWaitResult(&dummy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode KAddressArbiter::WaitIfEqual(VAddr addr, s32 value, s64 timeout) {
|
ResultCode KAddressArbiter::WaitIfEqual(VAddr addr, s32 value, s64 timeout) {
|
||||||
|
@ -292,7 +291,7 @@ ResultCode KAddressArbiter::WaitIfEqual(VAddr addr, s32 value, s64 timeout) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the synced object.
|
// Set the synced object.
|
||||||
cur_thread->SetSyncedObject(nullptr, ResultTimedOut);
|
cur_thread->SetWaitResult(ResultTimedOut);
|
||||||
|
|
||||||
// Read the value from userspace.
|
// Read the value from userspace.
|
||||||
s32 user_value{};
|
s32 user_value{};
|
||||||
|
@ -334,8 +333,7 @@ ResultCode KAddressArbiter::WaitIfEqual(VAddr addr, s32 value, s64 timeout) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the result.
|
// Get the result.
|
||||||
KSynchronizationObject* dummy{};
|
return cur_thread->GetWaitResult();
|
||||||
return cur_thread->GetWaitResult(&dummy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
|
|
@ -84,14 +84,14 @@ ResultCode KConditionVariable::SignalToAddress(VAddr addr) {
|
||||||
next_value |= Svc::HandleWaitMask;
|
next_value |= Svc::HandleWaitMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
next_owner_thread->SetSyncedObject(nullptr, ResultSuccess);
|
next_owner_thread->SetWaitResult(ResultSuccess);
|
||||||
next_owner_thread->Wakeup();
|
next_owner_thread->Wakeup();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the value to userspace.
|
// Write the value to userspace.
|
||||||
if (!WriteToUser(system, addr, std::addressof(next_value))) {
|
if (!WriteToUser(system, addr, std::addressof(next_value))) {
|
||||||
if (next_owner_thread) {
|
if (next_owner_thread) {
|
||||||
next_owner_thread->SetSyncedObject(nullptr, ResultInvalidCurrentMemory);
|
next_owner_thread->SetWaitResult(ResultInvalidCurrentMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResultInvalidCurrentMemory;
|
return ResultInvalidCurrentMemory;
|
||||||
|
@ -110,7 +110,7 @@ ResultCode KConditionVariable::WaitForAddress(Handle handle, VAddr addr, u32 val
|
||||||
ASSERT(owner_thread.IsNull());
|
ASSERT(owner_thread.IsNull());
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl(kernel);
|
KScopedSchedulerLock sl(kernel);
|
||||||
cur_thread->SetSyncedObject(nullptr, ResultSuccess);
|
cur_thread->SetWaitResult(ResultSuccess);
|
||||||
|
|
||||||
// Check if the thread should terminate.
|
// Check if the thread should terminate.
|
||||||
R_UNLESS(!cur_thread->IsTerminationRequested(), ResultTerminationRequested);
|
R_UNLESS(!cur_thread->IsTerminationRequested(), ResultTerminationRequested);
|
||||||
|
@ -151,8 +151,7 @@ ResultCode KConditionVariable::WaitForAddress(Handle handle, VAddr addr, u32 val
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the wait result.
|
// Get the wait result.
|
||||||
KSynchronizationObject* dummy{};
|
return cur_thread->GetWaitResult();
|
||||||
return cur_thread->GetWaitResult(std::addressof(dummy));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KThread* KConditionVariable::SignalImpl(KThread* thread) {
|
KThread* KConditionVariable::SignalImpl(KThread* thread) {
|
||||||
|
@ -179,7 +178,7 @@ KThread* KConditionVariable::SignalImpl(KThread* thread) {
|
||||||
if (can_access) {
|
if (can_access) {
|
||||||
if (prev_tag == Svc::InvalidHandle) {
|
if (prev_tag == Svc::InvalidHandle) {
|
||||||
// If nobody held the lock previously, we're all good.
|
// If nobody held the lock previously, we're all good.
|
||||||
thread->SetSyncedObject(nullptr, ResultSuccess);
|
thread->SetWaitResult(ResultSuccess);
|
||||||
thread->Wakeup();
|
thread->Wakeup();
|
||||||
} else {
|
} else {
|
||||||
// Get the previous owner.
|
// Get the previous owner.
|
||||||
|
@ -195,13 +194,13 @@ KThread* KConditionVariable::SignalImpl(KThread* thread) {
|
||||||
thread_to_close = owner_thread;
|
thread_to_close = owner_thread;
|
||||||
} else {
|
} else {
|
||||||
// The lock was tagged with a thread that doesn't exist.
|
// The lock was tagged with a thread that doesn't exist.
|
||||||
thread->SetSyncedObject(nullptr, ResultInvalidState);
|
thread->SetWaitResult(ResultInvalidState);
|
||||||
thread->Wakeup();
|
thread->Wakeup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If the address wasn't accessible, note so.
|
// If the address wasn't accessible, note so.
|
||||||
thread->SetSyncedObject(nullptr, ResultInvalidCurrentMemory);
|
thread->SetWaitResult(ResultInvalidCurrentMemory);
|
||||||
thread->Wakeup();
|
thread->Wakeup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +264,7 @@ ResultCode KConditionVariable::Wait(VAddr addr, u64 key, u32 value, s64 timeout)
|
||||||
KScopedSchedulerLockAndSleep slp{kernel, cur_thread, timeout};
|
KScopedSchedulerLockAndSleep slp{kernel, cur_thread, timeout};
|
||||||
|
|
||||||
// Set the synced object.
|
// Set the synced object.
|
||||||
cur_thread->SetSyncedObject(nullptr, ResultTimedOut);
|
cur_thread->SetWaitResult(ResultTimedOut);
|
||||||
|
|
||||||
// Check that the thread isn't terminating.
|
// Check that the thread isn't terminating.
|
||||||
if (cur_thread->IsTerminationRequested()) {
|
if (cur_thread->IsTerminationRequested()) {
|
||||||
|
@ -290,7 +289,7 @@ ResultCode KConditionVariable::Wait(VAddr addr, u64 key, u32 value, s64 timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wake up the next owner.
|
// Wake up the next owner.
|
||||||
next_owner_thread->SetSyncedObject(nullptr, ResultSuccess);
|
next_owner_thread->SetWaitResult(ResultSuccess);
|
||||||
next_owner_thread->Wakeup();
|
next_owner_thread->Wakeup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,8 +339,7 @@ ResultCode KConditionVariable::Wait(VAddr addr, u64 key, u32 value, s64 timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the result.
|
// Get the result.
|
||||||
KSynchronizationObject* dummy{};
|
return cur_thread->GetWaitResult();
|
||||||
return cur_thread->GetWaitResult(std::addressof(dummy));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
|
|
@ -176,7 +176,7 @@ ResultCode KServerSession::CompleteSyncRequest(HLERequestContext& context) {
|
||||||
KScopedSchedulerLock lock(kernel);
|
KScopedSchedulerLock lock(kernel);
|
||||||
if (!context.IsThreadWaiting()) {
|
if (!context.IsThreadWaiting()) {
|
||||||
context.GetThread().Wakeup();
|
context.GetThread().Wakeup();
|
||||||
context.GetThread().SetSyncedObject(nullptr, result);
|
context.GetThread().SetWaitResult(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -130,9 +130,6 @@ ResultCode KThread::Initialize(KThreadFunction func, uintptr_t arg, VAddr user_s
|
||||||
priority = prio;
|
priority = prio;
|
||||||
base_priority = prio;
|
base_priority = prio;
|
||||||
|
|
||||||
// Set sync object and waiting lock to null.
|
|
||||||
synced_object = nullptr;
|
|
||||||
|
|
||||||
// Initialize sleeping queue.
|
// Initialize sleeping queue.
|
||||||
sleeping_queue = nullptr;
|
sleeping_queue = nullptr;
|
||||||
|
|
||||||
|
@ -279,7 +276,7 @@ void KThread::Finalize() {
|
||||||
while (it != waiter_list.end()) {
|
while (it != waiter_list.end()) {
|
||||||
// The thread shouldn't be a kernel waiter.
|
// The thread shouldn't be a kernel waiter.
|
||||||
it->SetLockOwner(nullptr);
|
it->SetLockOwner(nullptr);
|
||||||
it->SetSyncedObject(nullptr, ResultInvalidState);
|
it->SetWaitResult(ResultInvalidState);
|
||||||
it->Wakeup();
|
it->Wakeup();
|
||||||
it = waiter_list.erase(it);
|
it = waiter_list.erase(it);
|
||||||
}
|
}
|
||||||
|
@ -650,7 +647,7 @@ void KThread::WaitCancel() {
|
||||||
sleeping_queue->WakeupThread(this);
|
sleeping_queue->WakeupThread(this);
|
||||||
wait_cancelled = true;
|
wait_cancelled = true;
|
||||||
} else {
|
} else {
|
||||||
SetSyncedObject(nullptr, ResultCancelled);
|
SetWaitResult(ResultCancelled);
|
||||||
SetState(ThreadState::Runnable);
|
SetState(ThreadState::Runnable);
|
||||||
wait_cancelled = false;
|
wait_cancelled = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,11 +197,6 @@ public:
|
||||||
|
|
||||||
void Suspend();
|
void Suspend();
|
||||||
|
|
||||||
void SetSyncedObject(KSynchronizationObject* obj, ResultCode wait_res) {
|
|
||||||
synced_object = obj;
|
|
||||||
wait_result = wait_res;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr void SetSyncedIndex(s32 index) {
|
constexpr void SetSyncedIndex(s32 index) {
|
||||||
synced_index = index;
|
synced_index = index;
|
||||||
}
|
}
|
||||||
|
@ -212,18 +207,12 @@ public:
|
||||||
|
|
||||||
constexpr void SetWaitResult(ResultCode wait_res) {
|
constexpr void SetWaitResult(ResultCode wait_res) {
|
||||||
wait_result = wait_res;
|
wait_result = wait_res;
|
||||||
synced_object = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr ResultCode GetWaitResult() const {
|
constexpr ResultCode GetWaitResult() const {
|
||||||
return wait_result;
|
return wait_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] ResultCode GetWaitResult(KSynchronizationObject** out) const {
|
|
||||||
*out = synced_object;
|
|
||||||
return wait_result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the Thread Local Storage address of the current thread
|
* Returns the Thread Local Storage address of the current thread
|
||||||
* @returns VAddr of the thread's TLS
|
* @returns VAddr of the thread's TLS
|
||||||
|
@ -716,7 +705,6 @@ private:
|
||||||
KAffinityMask physical_affinity_mask{};
|
KAffinityMask physical_affinity_mask{};
|
||||||
u64 thread_id{};
|
u64 thread_id{};
|
||||||
std::atomic<s64> cpu_time{};
|
std::atomic<s64> cpu_time{};
|
||||||
KSynchronizationObject* synced_object{};
|
|
||||||
VAddr address_key{};
|
VAddr address_key{};
|
||||||
KProcess* parent{};
|
KProcess* parent{};
|
||||||
VAddr kernel_stack_top{};
|
VAddr kernel_stack_top{};
|
||||||
|
|
|
@ -325,8 +325,7 @@ static ResultCode SendSyncRequest(Core::System& system, Handle handle) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KSynchronizationObject* dummy{};
|
return thread->GetWaitResult();
|
||||||
return thread->GetWaitResult(std::addressof(dummy));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ResultCode SendSyncRequest32(Core::System& system, Handle handle) {
|
static ResultCode SendSyncRequest32(Core::System& system, Handle handle) {
|
||||||
|
|
Loading…
Reference in a new issue