From 91f10a1460ba480236b255e4a0135e09b796d5c8 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 6 Jan 2018 15:55:40 -0500 Subject: semaphore: Updates for Switch. --- src/core/hle/kernel/semaphore.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/core/hle/kernel/semaphore.cpp') 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> Semaphore::Create(s32 initial_count, s32 max_count, VAddr address, - std::string name) { - - if (initial_count > max_count) - return ERR_INVALID_COMBINATION_KERNEL; - +ResultVal> Semaphore::Create(VAddr guest_addr, VAddr mutex_addr, std::string name) { SharedPtr 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>(std::move(semaphore)); } @@ -39,18 +38,22 @@ void Semaphore::Acquire(Thread* thread) { if (available_count <= 0) return; --available_count; + UpdateGuestState(); } ResultVal 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(previous_count); } -} // namespace +void Semaphore::UpdateGuestState() { + Memory::Write32(guest_addr, available_count); +} + + +} // namespace Kernel -- cgit v1.2.3