summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/resource_limit.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2020-03-23 20:30:22 +0100
committerbunnei <bunneidev@gmail.com>2020-04-17 06:59:27 +0200
commitb0e3cbef7ae60736f356e346b9c1e52115db752f (patch)
treea8e9b02af9cb2a254e32aaa2d5b2d325039a06ea /src/core/hle/kernel/resource_limit.cpp
parentloader: nso: Fix loading of static objects to be properly sized and aligned. (diff)
downloadyuzu-b0e3cbef7ae60736f356e346b9c1e52115db752f.tar
yuzu-b0e3cbef7ae60736f356e346b9c1e52115db752f.tar.gz
yuzu-b0e3cbef7ae60736f356e346b9c1e52115db752f.tar.bz2
yuzu-b0e3cbef7ae60736f356e346b9c1e52115db752f.tar.lz
yuzu-b0e3cbef7ae60736f356e346b9c1e52115db752f.tar.xz
yuzu-b0e3cbef7ae60736f356e346b9c1e52115db752f.tar.zst
yuzu-b0e3cbef7ae60736f356e346b9c1e52115db752f.zip
Diffstat (limited to 'src/core/hle/kernel/resource_limit.cpp')
-rw-r--r--src/core/hle/kernel/resource_limit.cpp50
1 files changed, 42 insertions, 8 deletions
diff --git a/src/core/hle/kernel/resource_limit.cpp b/src/core/hle/kernel/resource_limit.cpp
index b53423462..96e5b9892 100644
--- a/src/core/hle/kernel/resource_limit.cpp
+++ b/src/core/hle/kernel/resource_limit.cpp
@@ -16,26 +16,60 @@ constexpr std::size_t ResourceTypeToIndex(ResourceType type) {
ResourceLimit::ResourceLimit(KernelCore& kernel) : Object{kernel} {}
ResourceLimit::~ResourceLimit() = default;
+bool ResourceLimit::Reserve(ResourceType resource, s64 amount) {
+ return Reserve(resource, amount, 10000000000);
+}
+
+bool ResourceLimit::Reserve(ResourceType resource, s64 amount, u64 timeout) {
+ const std::size_t index{ResourceTypeToIndex(resource)};
+
+ s64 new_value = current[index] + amount;
+ while (new_value > limit[index] && available[index] + amount <= limit[index]) {
+ // TODO(bunnei): This is wrong for multicore, we should wait the calling thread for timeout
+ new_value = current[index] + amount;
+
+ if (timeout >= 0) {
+ break;
+ }
+ }
+
+ if (new_value <= limit[index]) {
+ current[index] = new_value;
+ return true;
+ }
+ return false;
+}
+
+void ResourceLimit::Release(ResourceType resource, u64 amount) {
+ Release(resource, amount, amount);
+}
+
+void ResourceLimit::Release(ResourceType resource, u64 used_amount, u64 available_amount) {
+ const std::size_t index{ResourceTypeToIndex(resource)};
+
+ current[index] -= used_amount;
+ available[index] -= available_amount;
+}
+
std::shared_ptr<ResourceLimit> ResourceLimit::Create(KernelCore& kernel) {
return std::make_shared<ResourceLimit>(kernel);
}
s64 ResourceLimit::GetCurrentResourceValue(ResourceType resource) const {
- return values.at(ResourceTypeToIndex(resource));
+ return limit.at(ResourceTypeToIndex(resource)) - current.at(ResourceTypeToIndex(resource));
}
s64 ResourceLimit::GetMaxResourceValue(ResourceType resource) const {
- return limits.at(ResourceTypeToIndex(resource));
+ return limit.at(ResourceTypeToIndex(resource));
}
ResultCode ResourceLimit::SetLimitValue(ResourceType resource, s64 value) {
- const auto index = ResourceTypeToIndex(resource);
-
- if (value < values[index]) {
+ const std::size_t index{ResourceTypeToIndex(resource)};
+ if (current[index] <= value) {
+ limit[index] = value;
+ return RESULT_SUCCESS;
+ } else {
return ERR_INVALID_STATE;
}
-
- values[index] = value;
- return RESULT_SUCCESS;
}
} // namespace Kernel