diff options
author | Lioncash <mathew1800@gmail.com> | 2018-11-19 18:54:06 +0100 |
---|---|---|
committer | Lioncash <mathew1800@gmail.com> | 2018-11-20 00:16:39 +0100 |
commit | 5d46038c5cd91504b00b76660212a3a28b244f38 (patch) | |
tree | 01e29da6e94c76109225ae27ed92dbfe7973c22d /src/core/hle/kernel/resource_limit.cpp | |
parent | Merge pull request #1634 from DarkLordZach/better-hid-2 (diff) | |
download | yuzu-5d46038c5cd91504b00b76660212a3a28b244f38.tar yuzu-5d46038c5cd91504b00b76660212a3a28b244f38.tar.gz yuzu-5d46038c5cd91504b00b76660212a3a28b244f38.tar.bz2 yuzu-5d46038c5cd91504b00b76660212a3a28b244f38.tar.lz yuzu-5d46038c5cd91504b00b76660212a3a28b244f38.tar.xz yuzu-5d46038c5cd91504b00b76660212a3a28b244f38.tar.zst yuzu-5d46038c5cd91504b00b76660212a3a28b244f38.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/kernel/resource_limit.cpp | 75 |
1 files changed, 21 insertions, 54 deletions
diff --git a/src/core/hle/kernel/resource_limit.cpp b/src/core/hle/kernel/resource_limit.cpp index b253a680f..2f9695005 100644 --- a/src/core/hle/kernel/resource_limit.cpp +++ b/src/core/hle/kernel/resource_limit.cpp @@ -2,12 +2,16 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include <cstring> -#include "common/assert.h" -#include "common/logging/log.h" +#include "core/hle/kernel/errors.h" #include "core/hle/kernel/resource_limit.h" +#include "core/hle/result.h" namespace Kernel { +namespace { +constexpr std::size_t ResourceTypeToIndex(ResourceType type) { + return static_cast<std::size_t>(type); +} +} // Anonymous namespace ResourceLimit::ResourceLimit(KernelCore& kernel) : Object{kernel} {} ResourceLimit::~ResourceLimit() = default; @@ -19,59 +23,22 @@ SharedPtr<ResourceLimit> ResourceLimit::Create(KernelCore& kernel, std::string n return resource_limit; } -s32 ResourceLimit::GetCurrentResourceValue(ResourceType resource) const { - switch (resource) { - case ResourceType::Commit: - return current_commit; - case ResourceType::Thread: - return current_threads; - case ResourceType::Event: - return current_events; - case ResourceType::Mutex: - return current_mutexes; - case ResourceType::Semaphore: - return current_semaphores; - case ResourceType::Timer: - return current_timers; - case ResourceType::SharedMemory: - return current_shared_mems; - case ResourceType::AddressArbiter: - return current_address_arbiters; - case ResourceType::CPUTime: - return current_cpu_time; - default: - LOG_ERROR(Kernel, "Unknown resource type={:08X}", static_cast<u32>(resource)); - UNIMPLEMENTED(); - return 0; - } +s64 ResourceLimit::GetCurrentResourceValue(ResourceType resource) const { + return values.at(ResourceTypeToIndex(resource)); +} + +s64 ResourceLimit::GetMaxResourceValue(ResourceType resource) const { + return limits.at(ResourceTypeToIndex(resource)); } -u32 ResourceLimit::GetMaxResourceValue(ResourceType resource) const { - switch (resource) { - case ResourceType::Priority: - return max_priority; - case ResourceType::Commit: - return max_commit; - case ResourceType::Thread: - return max_threads; - case ResourceType::Event: - return max_events; - case ResourceType::Mutex: - return max_mutexes; - case ResourceType::Semaphore: - return max_semaphores; - case ResourceType::Timer: - return max_timers; - case ResourceType::SharedMemory: - return max_shared_mems; - case ResourceType::AddressArbiter: - return max_address_arbiters; - case ResourceType::CPUTime: - return max_cpu_time; - default: - LOG_ERROR(Kernel, "Unknown resource type={:08X}", static_cast<u32>(resource)); - UNIMPLEMENTED(); - return 0; +ResultCode ResourceLimit::SetLimitValue(ResourceType resource, s64 value) { + const auto index = ResourceTypeToIndex(resource); + + if (value < values[index]) { + return ERR_INVALID_STATE; } + + values[index] = value; + return RESULT_SUCCESS; } } // namespace Kernel |