summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/semaphore.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2018-01-06 21:55:40 +0100
committerbunnei <bunneidev@gmail.com>2018-01-06 21:55:40 +0100
commit91f10a1460ba480236b255e4a0135e09b796d5c8 (patch)
tree9db334faf1a1a562aadba4ba78888b1222f5cdab /src/core/hle/kernel/semaphore.cpp
parentlm: Assert on unsupported multi-message. (diff)
downloadyuzu-91f10a1460ba480236b255e4a0135e09b796d5c8.tar
yuzu-91f10a1460ba480236b255e4a0135e09b796d5c8.tar.gz
yuzu-91f10a1460ba480236b255e4a0135e09b796d5c8.tar.bz2
yuzu-91f10a1460ba480236b255e4a0135e09b796d5c8.tar.lz
yuzu-91f10a1460ba480236b255e4a0135e09b796d5c8.tar.xz
yuzu-91f10a1460ba480236b255e4a0135e09b796d5c8.tar.zst
yuzu-91f10a1460ba480236b255e4a0135e09b796d5c8.zip
Diffstat (limited to '')
-rw-r--r--src/core/hle/kernel/semaphore.cpp31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/core/hle/kernel/semaphore.cpp b/src/core/hle/kernel/semaphore.cpp
index 2605b2595..3f364661b 100644
--- a/src/core/hle/kernel/semaphore.cpp
+++ b/src/core/hle/kernel/semaphore.cpp
@@ -5,6 +5,7 @@
#include "common/assert.h"
#include "core/hle/kernel/errors.h"
#include "core/hle/kernel/kernel.h"
+#include "core/hle/kernel/object_address_table.h"
#include "core/hle/kernel/semaphore.h"
#include "core/hle/kernel/thread.h"
@@ -13,20 +14,18 @@ namespace Kernel {
Semaphore::Semaphore() {}
Semaphore::~Semaphore() {}
-ResultVal<SharedPtr<Semaphore>> Semaphore::Create(s32 initial_count, s32 max_count, VAddr address,
- std::string name) {
-
- if (initial_count > max_count)
- return ERR_INVALID_COMBINATION_KERNEL;
-
+ResultVal<SharedPtr<Semaphore>> Semaphore::Create(VAddr guest_addr, VAddr mutex_addr, 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->max_count = max_count;
- semaphore->available_count = initial_count;
- semaphore->address = address;
+ // 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;
+
+ // Semaphores are referenced by guest address, so track this in the kernel
+ g_object_address_table.Insert(guest_addr, semaphore);
return MakeResult<SharedPtr<Semaphore>>(std::move(semaphore));
}
@@ -39,18 +38,22 @@ void Semaphore::Acquire(Thread* thread) {
if (available_count <= 0)
return;
--available_count;
+ UpdateGuestState();
}
ResultVal<s32> Semaphore::Release(s32 release_count) {
- if (max_count - available_count < release_count)
- return ERR_OUT_OF_RANGE_KERNEL;
-
s32 previous_count = available_count;
available_count += release_count;
+ UpdateGuestState();
WakeupAllWaitingThreads();
return MakeResult<s32>(previous_count);
}
-} // namespace
+void Semaphore::UpdateGuestState() {
+ Memory::Write32(guest_addr, available_count);
+}
+
+
+} // namespace Kernel