summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/svc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/svc.cpp')
-rw-r--r--src/core/hle/kernel/svc.cpp58
1 files changed, 33 insertions, 25 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index d18d7a182..b94503536 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -1,4 +1,4 @@
1// Copyright 2014 Citra Emulator Project 1// Copyright 2018 Yuzu Emulator Team
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
@@ -8,12 +8,12 @@
8#include "core/core_timing.h" 8#include "core/core_timing.h"
9#include "core/hle/kernel/client_port.h" 9#include "core/hle/kernel/client_port.h"
10#include "core/hle/kernel/client_session.h" 10#include "core/hle/kernel/client_session.h"
11#include "core/hle/kernel/condition_variable.h"
11#include "core/hle/kernel/handle_table.h" 12#include "core/hle/kernel/handle_table.h"
12#include "core/hle/kernel/mutex.h" 13#include "core/hle/kernel/mutex.h"
13#include "core/hle/kernel/object_address_table.h" 14#include "core/hle/kernel/object_address_table.h"
14#include "core/hle/kernel/process.h" 15#include "core/hle/kernel/process.h"
15#include "core/hle/kernel/resource_limit.h" 16#include "core/hle/kernel/resource_limit.h"
16#include "core/hle/kernel/semaphore.h"
17#include "core/hle/kernel/svc.h" 17#include "core/hle/kernel/svc.h"
18#include "core/hle/kernel/svc_wrap.h" 18#include "core/hle/kernel/svc_wrap.h"
19#include "core/hle/kernel/sync_object.h" 19#include "core/hle/kernel/sync_object.h"
@@ -476,11 +476,12 @@ static void SleepThread(s64 nanoseconds) {
476} 476}
477 477
478/// Signal process wide key atomic 478/// Signal process wide key atomic
479static ResultCode WaitProcessWideKeyAtomic(VAddr mutex_addr, VAddr semaphore_addr, 479static ResultCode WaitProcessWideKeyAtomic(VAddr mutex_addr, VAddr condition_variable_addr,
480 Handle thread_handle, s64 nano_seconds) { 480 Handle thread_handle, s64 nano_seconds) {
481 LOG_TRACE(Kernel_SVC, 481 LOG_TRACE(
482 "called mutex_addr=%llx, semaphore_addr=%llx, thread_handle=0x%08X, timeout=%d", 482 Kernel_SVC,
483 mutex_addr, semaphore_addr, thread_handle, nano_seconds); 483 "called mutex_addr=%llx, condition_variable_addr=%llx, thread_handle=0x%08X, timeout=%d",
484 mutex_addr, condition_variable_addr, thread_handle, nano_seconds);
484 485
485 SharedPtr<Thread> thread = g_handle_table.Get<Thread>(thread_handle); 486 SharedPtr<Thread> thread = g_handle_table.Get<Thread>(thread_handle);
486 ASSERT(thread); 487 ASSERT(thread);
@@ -494,15 +495,18 @@ static ResultCode WaitProcessWideKeyAtomic(VAddr mutex_addr, VAddr semaphore_add
494 495
495 ASSERT(mutex->GetOwnerHandle() == thread_handle); 496 ASSERT(mutex->GetOwnerHandle() == thread_handle);
496 497
497 SharedPtr<Semaphore> semaphore = g_object_address_table.Get<Semaphore>(semaphore_addr); 498 SharedPtr<ConditionVariable> condition_variable =
498 if (!semaphore) { 499 g_object_address_table.Get<ConditionVariable>(condition_variable_addr);
499 // Create a new semaphore for the specified address if one does not already exist 500 if (!condition_variable) {
500 semaphore = Semaphore::Create(semaphore_addr, mutex_addr).Unwrap(); 501 // Create a new condition_variable for the specified address if one does not already exist
501 semaphore->name = Common::StringFromFormat("semaphore-%llx", semaphore_addr); 502 condition_variable =
503 ConditionVariable::Create(condition_variable_addr, mutex_addr).Unwrap();
504 condition_variable->name =
505 Common::StringFromFormat("condition-variable-%llx", condition_variable_addr);
502 } 506 }
503 507
504 ASSERT(semaphore->GetAvailableCount() == 0); 508 ASSERT(condition_variable->GetAvailableCount() == 0);
505 ASSERT(semaphore->mutex_addr == mutex_addr); 509 ASSERT(condition_variable->mutex_addr == mutex_addr);
506 510
507 auto wakeup_callback = [mutex, nano_seconds](ThreadWakeupReason reason, 511 auto wakeup_callback = [mutex, nano_seconds](ThreadWakeupReason reason,
508 SharedPtr<Thread> thread, 512 SharedPtr<Thread> thread,
@@ -541,7 +545,8 @@ static ResultCode WaitProcessWideKeyAtomic(VAddr mutex_addr, VAddr semaphore_add
541 545
542 return false; 546 return false;
543 }; 547 };
544 CASCADE_CODE(WaitSynchronization1(semaphore, thread.get(), nano_seconds, wakeup_callback)); 548 CASCADE_CODE(
549 WaitSynchronization1(condition_variable, thread.get(), nano_seconds, wakeup_callback));
545 550
546 mutex->Release(thread.get()); 551 mutex->Release(thread.get());
547 552
@@ -549,24 +554,27 @@ static ResultCode WaitProcessWideKeyAtomic(VAddr mutex_addr, VAddr semaphore_add
549} 554}
550 555
551/// Signal process wide key 556/// Signal process wide key
552static ResultCode SignalProcessWideKey(VAddr semaphore_addr, s32 target) { 557static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target) {
553 LOG_TRACE(Kernel_SVC, "called, semaphore_addr=0x%llx, target=0x%08x", semaphore_addr, target); 558 LOG_TRACE(Kernel_SVC, "called, condition_variable_addr=0x%llx, target=0x%08x",
559 condition_variable_addr, target);
554 560
555 // Wakeup all or one thread - Any other value is unimplemented 561 // Wakeup all or one thread - Any other value is unimplemented
556 ASSERT(target == -1 || target == 1); 562 ASSERT(target == -1 || target == 1);
557 563
558 SharedPtr<Semaphore> semaphore = g_object_address_table.Get<Semaphore>(semaphore_addr); 564 SharedPtr<ConditionVariable> condition_variable =
559 if (!semaphore) { 565 g_object_address_table.Get<ConditionVariable>(condition_variable_addr);
560 // Create a new semaphore for the specified address if one does not already exist 566 if (!condition_variable) {
561 semaphore = Semaphore::Create(semaphore_addr).Unwrap(); 567 // Create a new condition_variable for the specified address if one does not already exist
562 semaphore->name = Common::StringFromFormat("semaphore-%llx", semaphore_addr); 568 condition_variable = ConditionVariable::Create(condition_variable_addr).Unwrap();
569 condition_variable->name =
570 Common::StringFromFormat("condition-variable-%llx", condition_variable_addr);
563 } 571 }
564 572
565 CASCADE_CODE(semaphore->Release(target)); 573 CASCADE_CODE(condition_variable->Release(target));
566 574
567 if (semaphore->mutex_addr) { 575 if (condition_variable->mutex_addr) {
568 // If a mutex was created for this semaphore, wait the current thread on it 576 // If a mutex was created for this condition_variable, wait the current thread on it
569 SharedPtr<Mutex> mutex = g_object_address_table.Get<Mutex>(semaphore->mutex_addr); 577 SharedPtr<Mutex> mutex = g_object_address_table.Get<Mutex>(condition_variable->mutex_addr);
570 return WaitSynchronization1(mutex, GetCurrentThread()); 578 return WaitSynchronization1(mutex, GetCurrentThread());
571 } 579 }
572 580