summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/semaphore.cpp
diff options
context:
space:
mode:
authorSubv <subv2112@gmail.com>2018-01-08 20:14:30 +0100
committerbunnei <bunneidev@gmail.com>2018-01-09 03:12:54 +0100
commitdb3a5251664ae77f5e67dba571a11d208e448a86 (patch)
treef53b53b9620ca36a5b8085e3e9d2b603477142fc /src/core/hle/kernel/semaphore.cpp
parentKernel: Properly keep track of mutex lock data in the guest memory. This fixes userland locking/unlocking. (diff)
downloadyuzu-db3a5251664ae77f5e67dba571a11d208e448a86.tar
yuzu-db3a5251664ae77f5e67dba571a11d208e448a86.tar.gz
yuzu-db3a5251664ae77f5e67dba571a11d208e448a86.tar.bz2
yuzu-db3a5251664ae77f5e67dba571a11d208e448a86.tar.lz
yuzu-db3a5251664ae77f5e67dba571a11d208e448a86.tar.xz
yuzu-db3a5251664ae77f5e67dba571a11d208e448a86.tar.zst
yuzu-db3a5251664ae77f5e67dba571a11d208e448a86.zip
Diffstat (limited to 'src/core/hle/kernel/semaphore.cpp')
-rw-r--r--src/core/hle/kernel/semaphore.cpp23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/core/hle/kernel/semaphore.cpp b/src/core/hle/kernel/semaphore.cpp
index 9c58aa42f..b555bb28e 100644
--- a/src/core/hle/kernel/semaphore.cpp
+++ b/src/core/hle/kernel/semaphore.cpp
@@ -18,9 +18,6 @@ ResultVal<SharedPtr<Semaphore>> Semaphore::Create(VAddr guest_addr, VAddr mutex_
std::string name) {
SharedPtr<Semaphore> semaphore(new Semaphore);
- // When the semaphore is created, some slots are reserved for other threads,
- // and the rest is reserved for the caller thread;
- semaphore->available_count = Memory::Read32(guest_addr);
semaphore->name = std::move(name);
semaphore->guest_addr = guest_addr;
semaphore->mutex_addr = mutex_addr;
@@ -32,34 +29,36 @@ ResultVal<SharedPtr<Semaphore>> Semaphore::Create(VAddr guest_addr, VAddr mutex_
}
bool Semaphore::ShouldWait(Thread* thread) const {
- return available_count <= 0;
+ return GetAvailableCount() <= 0;
}
void Semaphore::Acquire(Thread* thread) {
- if (available_count <= 0)
+ if (GetAvailableCount() <= 0)
return;
- --available_count;
- UpdateGuestState();
+ SetAvailableCount(GetAvailableCount() - 1);
}
ResultCode Semaphore::Release(s32 target) {
- ++available_count;
- UpdateGuestState();
-
if (target == -1) {
// When -1, wake up all waiting threads
+ SetAvailableCount(GetWaitingThreads().size());
WakeupAllWaitingThreads();
} else {
// Otherwise, wake up just a single thread
+ SetAvailableCount(target);
WakeupWaitingThread(GetHighestPriorityReadyThread());
}
return RESULT_SUCCESS;
}
-void Semaphore::UpdateGuestState() {
- Memory::Write32(guest_addr, available_count);
+s32 Semaphore::GetAvailableCount() const {
+ return Memory::Read32(guest_addr);
+}
+
+void Semaphore::SetAvailableCount(s32 value) const {
+ Memory::Write32(guest_addr, value);
}
} // namespace Kernel