summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/process.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2021-01-11 14:36:26 -0800
committerGravatar GitHub2021-01-11 14:36:26 -0800
commiteb3cb54aa53e23af61afb9b7e35af28c9d37ae2a (patch)
tree56a80760bd0ba8ecd85dc8d9f09fb9e2068c91d4 /src/core/hle/kernel/process.cpp
parentMerge pull request #5229 from Morph1984/fullscreen-opt (diff)
parenthle: kernel: thread: Preserve thread wait reason for debugging only. (diff)
downloadyuzu-eb3cb54aa53e23af61afb9b7e35af28c9d37ae2a.tar.gz
yuzu-eb3cb54aa53e23af61afb9b7e35af28c9d37ae2a.tar.xz
yuzu-eb3cb54aa53e23af61afb9b7e35af28c9d37ae2a.zip
Merge pull request #5266 from bunnei/kernel-synch
Rewrite KSynchronizationObject, KConditonVariable, and KAddressArbiter
Diffstat (limited to 'src/core/hle/kernel/process.cpp')
-rw-r--r--src/core/hle/kernel/process.cpp67
1 files changed, 11 insertions, 56 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index b905b486a..37b77fa6e 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -55,7 +55,7 @@ void SetupMainThread(Core::System& system, Process& owner_process, u32 priority,
55 // Threads by default are dormant, wake up the main thread so it runs when the scheduler fires 55 // Threads by default are dormant, wake up the main thread so it runs when the scheduler fires
56 { 56 {
57 KScopedSchedulerLock lock{kernel}; 57 KScopedSchedulerLock lock{kernel};
58 thread->SetStatus(ThreadStatus::Ready); 58 thread->SetState(ThreadState::Runnable);
59 } 59 }
60} 60}
61} // Anonymous namespace 61} // Anonymous namespace
@@ -162,48 +162,6 @@ u64 Process::GetTotalPhysicalMemoryUsedWithoutSystemResource() const {
162 return GetTotalPhysicalMemoryUsed() - GetSystemResourceUsage(); 162 return GetTotalPhysicalMemoryUsed() - GetSystemResourceUsage();
163} 163}
164 164
165void Process::InsertConditionVariableThread(std::shared_ptr<Thread> thread) {
166 VAddr cond_var_addr = thread->GetCondVarWaitAddress();
167 std::list<std::shared_ptr<Thread>>& thread_list = cond_var_threads[cond_var_addr];
168 auto it = thread_list.begin();
169 while (it != thread_list.end()) {
170 const std::shared_ptr<Thread> current_thread = *it;
171 if (current_thread->GetPriority() > thread->GetPriority()) {
172 thread_list.insert(it, thread);
173 return;
174 }
175 ++it;
176 }
177 thread_list.push_back(thread);
178}
179
180void Process::RemoveConditionVariableThread(std::shared_ptr<Thread> thread) {
181 VAddr cond_var_addr = thread->GetCondVarWaitAddress();
182 std::list<std::shared_ptr<Thread>>& thread_list = cond_var_threads[cond_var_addr];
183 auto it = thread_list.begin();
184 while (it != thread_list.end()) {
185 const std::shared_ptr<Thread> current_thread = *it;
186 if (current_thread.get() == thread.get()) {
187 thread_list.erase(it);
188 return;
189 }
190 ++it;
191 }
192}
193
194std::vector<std::shared_ptr<Thread>> Process::GetConditionVariableThreads(
195 const VAddr cond_var_addr) {
196 std::vector<std::shared_ptr<Thread>> result{};
197 std::list<std::shared_ptr<Thread>>& thread_list = cond_var_threads[cond_var_addr];
198 auto it = thread_list.begin();
199 while (it != thread_list.end()) {
200 std::shared_ptr<Thread> current_thread = *it;
201 result.push_back(current_thread);
202 ++it;
203 }
204 return result;
205}
206
207void Process::RegisterThread(const Thread* thread) { 165void Process::RegisterThread(const Thread* thread) {
208 thread_list.push_back(thread); 166 thread_list.push_back(thread);
209} 167}
@@ -318,7 +276,7 @@ void Process::PrepareForTermination() {
318 continue; 276 continue;
319 277
320 // TODO(Subv): When are the other running/ready threads terminated? 278 // TODO(Subv): When are the other running/ready threads terminated?
321 ASSERT_MSG(thread->GetStatus() == ThreadStatus::WaitSynch, 279 ASSERT_MSG(thread->GetState() == ThreadState::Waiting,
322 "Exiting processes with non-waiting threads is currently unimplemented"); 280 "Exiting processes with non-waiting threads is currently unimplemented");
323 281
324 thread->Stop(); 282 thread->Stop();
@@ -406,21 +364,18 @@ void Process::LoadModule(CodeSet code_set, VAddr base_addr) {
406 ReprotectSegment(code_set.DataSegment(), Memory::MemoryPermission::ReadAndWrite); 364 ReprotectSegment(code_set.DataSegment(), Memory::MemoryPermission::ReadAndWrite);
407} 365}
408 366
367bool Process::IsSignaled() const {
368 ASSERT(kernel.GlobalSchedulerContext().IsLocked());
369 return is_signaled;
370}
371
409Process::Process(Core::System& system) 372Process::Process(Core::System& system)
410 : SynchronizationObject{system.Kernel()}, page_table{std::make_unique<Memory::PageTable>( 373 : KSynchronizationObject{system.Kernel()},
411 system)}, 374 page_table{std::make_unique<Memory::PageTable>(system)}, handle_table{system.Kernel()},
412 handle_table{system.Kernel()}, address_arbiter{system}, mutex{system}, system{system} {} 375 address_arbiter{system}, condition_var{system}, system{system} {}
413 376
414Process::~Process() = default; 377Process::~Process() = default;
415 378
416void Process::Acquire(Thread* thread) {
417 ASSERT_MSG(!ShouldWait(thread), "Object unavailable!");
418}
419
420bool Process::ShouldWait(const Thread* thread) const {
421 return !is_signaled;
422}
423
424void Process::ChangeStatus(ProcessStatus new_status) { 379void Process::ChangeStatus(ProcessStatus new_status) {
425 if (status == new_status) { 380 if (status == new_status) {
426 return; 381 return;
@@ -428,7 +383,7 @@ void Process::ChangeStatus(ProcessStatus new_status) {
428 383
429 status = new_status; 384 status = new_status;
430 is_signaled = true; 385 is_signaled = true;
431 Signal(); 386 NotifyAvailable();
432} 387}
433 388
434ResultCode Process::AllocateMainThreadStack(std::size_t stack_size) { 389ResultCode Process::AllocateMainThreadStack(std::size_t stack_size) {