diff options
| author | 2023-03-07 10:58:51 -0500 | |
|---|---|---|
| committer | 2023-03-12 22:09:09 -0400 | |
| commit | 641783df8f225bb455383747ee2d241c6458214a (patch) | |
| tree | f3d97539888feefec6c486adace9480b70ce43be | |
| parent | kernel: remove kernel_ (diff) | |
| download | yuzu-641783df8f225bb455383747ee2d241c6458214a.tar.gz yuzu-641783df8f225bb455383747ee2d241c6458214a.tar.xz yuzu-641783df8f225bb455383747ee2d241c6458214a.zip | |
kernel: convert KResourceLimit
| -rw-r--r-- | src/core/hle/kernel/k_resource_limit.cpp | 98 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_resource_limit.h | 20 |
2 files changed, 59 insertions, 59 deletions
diff --git a/src/core/hle/kernel/k_resource_limit.cpp b/src/core/hle/kernel/k_resource_limit.cpp index e224e1622..b5c353938 100644 --- a/src/core/hle/kernel/k_resource_limit.cpp +++ b/src/core/hle/kernel/k_resource_limit.cpp | |||
| @@ -12,11 +12,11 @@ namespace Kernel { | |||
| 12 | constexpr s64 DefaultTimeout = 10000000000; // 10 seconds | 12 | constexpr s64 DefaultTimeout = 10000000000; // 10 seconds |
| 13 | 13 | ||
| 14 | KResourceLimit::KResourceLimit(KernelCore& kernel) | 14 | KResourceLimit::KResourceLimit(KernelCore& kernel) |
| 15 | : KAutoObjectWithSlabHeapAndContainer{kernel}, lock{kernel}, cond_var{kernel} {} | 15 | : KAutoObjectWithSlabHeapAndContainer{kernel}, m_lock{m_kernel}, m_cond_var{m_kernel} {} |
| 16 | KResourceLimit::~KResourceLimit() = default; | 16 | KResourceLimit::~KResourceLimit() = default; |
| 17 | 17 | ||
| 18 | void KResourceLimit::Initialize(const Core::Timing::CoreTiming* core_timing_) { | 18 | void KResourceLimit::Initialize(const Core::Timing::CoreTiming* core_timing) { |
| 19 | core_timing = core_timing_; | 19 | m_core_timing = core_timing; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | void KResourceLimit::Finalize() {} | 22 | void KResourceLimit::Finalize() {} |
| @@ -25,11 +25,11 @@ s64 KResourceLimit::GetLimitValue(LimitableResource which) const { | |||
| 25 | const auto index = static_cast<std::size_t>(which); | 25 | const auto index = static_cast<std::size_t>(which); |
| 26 | s64 value{}; | 26 | s64 value{}; |
| 27 | { | 27 | { |
| 28 | KScopedLightLock lk{lock}; | 28 | KScopedLightLock lk{m_lock}; |
| 29 | value = limit_values[index]; | 29 | value = m_limit_values[index]; |
| 30 | ASSERT(value >= 0); | 30 | ASSERT(value >= 0); |
| 31 | ASSERT(current_values[index] <= limit_values[index]); | 31 | ASSERT(m_current_values[index] <= m_limit_values[index]); |
| 32 | ASSERT(current_hints[index] <= current_values[index]); | 32 | ASSERT(m_current_hints[index] <= m_current_values[index]); |
| 33 | } | 33 | } |
| 34 | return value; | 34 | return value; |
| 35 | } | 35 | } |
| @@ -38,11 +38,11 @@ s64 KResourceLimit::GetCurrentValue(LimitableResource which) const { | |||
| 38 | const auto index = static_cast<std::size_t>(which); | 38 | const auto index = static_cast<std::size_t>(which); |
| 39 | s64 value{}; | 39 | s64 value{}; |
| 40 | { | 40 | { |
| 41 | KScopedLightLock lk{lock}; | 41 | KScopedLightLock lk{m_lock}; |
| 42 | value = current_values[index]; | 42 | value = m_current_values[index]; |
| 43 | ASSERT(value >= 0); | 43 | ASSERT(value >= 0); |
| 44 | ASSERT(current_values[index] <= limit_values[index]); | 44 | ASSERT(m_current_values[index] <= m_limit_values[index]); |
| 45 | ASSERT(current_hints[index] <= current_values[index]); | 45 | ASSERT(m_current_hints[index] <= m_current_values[index]); |
| 46 | } | 46 | } |
| 47 | return value; | 47 | return value; |
| 48 | } | 48 | } |
| @@ -51,11 +51,11 @@ s64 KResourceLimit::GetPeakValue(LimitableResource which) const { | |||
| 51 | const auto index = static_cast<std::size_t>(which); | 51 | const auto index = static_cast<std::size_t>(which); |
| 52 | s64 value{}; | 52 | s64 value{}; |
| 53 | { | 53 | { |
| 54 | KScopedLightLock lk{lock}; | 54 | KScopedLightLock lk{m_lock}; |
| 55 | value = peak_values[index]; | 55 | value = m_peak_values[index]; |
| 56 | ASSERT(value >= 0); | 56 | ASSERT(value >= 0); |
| 57 | ASSERT(current_values[index] <= limit_values[index]); | 57 | ASSERT(m_current_values[index] <= m_limit_values[index]); |
| 58 | ASSERT(current_hints[index] <= current_values[index]); | 58 | ASSERT(m_current_hints[index] <= m_current_values[index]); |
| 59 | } | 59 | } |
| 60 | return value; | 60 | return value; |
| 61 | } | 61 | } |
| @@ -64,11 +64,11 @@ s64 KResourceLimit::GetFreeValue(LimitableResource which) const { | |||
| 64 | const auto index = static_cast<std::size_t>(which); | 64 | const auto index = static_cast<std::size_t>(which); |
| 65 | s64 value{}; | 65 | s64 value{}; |
| 66 | { | 66 | { |
| 67 | KScopedLightLock lk(lock); | 67 | KScopedLightLock lk(m_lock); |
| 68 | ASSERT(current_values[index] >= 0); | 68 | ASSERT(m_current_values[index] >= 0); |
| 69 | ASSERT(current_values[index] <= limit_values[index]); | 69 | ASSERT(m_current_values[index] <= m_limit_values[index]); |
| 70 | ASSERT(current_hints[index] <= current_values[index]); | 70 | ASSERT(m_current_hints[index] <= m_current_values[index]); |
| 71 | value = limit_values[index] - current_values[index]; | 71 | value = m_limit_values[index] - m_current_values[index]; |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | return value; | 74 | return value; |
| @@ -76,51 +76,51 @@ s64 KResourceLimit::GetFreeValue(LimitableResource which) const { | |||
| 76 | 76 | ||
| 77 | Result KResourceLimit::SetLimitValue(LimitableResource which, s64 value) { | 77 | Result KResourceLimit::SetLimitValue(LimitableResource which, s64 value) { |
| 78 | const auto index = static_cast<std::size_t>(which); | 78 | const auto index = static_cast<std::size_t>(which); |
| 79 | KScopedLightLock lk(lock); | 79 | KScopedLightLock lk(m_lock); |
| 80 | R_UNLESS(current_values[index] <= value, ResultInvalidState); | 80 | R_UNLESS(m_current_values[index] <= value, ResultInvalidState); |
| 81 | 81 | ||
| 82 | limit_values[index] = value; | 82 | m_limit_values[index] = value; |
| 83 | peak_values[index] = current_values[index]; | 83 | m_peak_values[index] = m_current_values[index]; |
| 84 | 84 | ||
| 85 | R_SUCCEED(); | 85 | R_SUCCEED(); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | bool KResourceLimit::Reserve(LimitableResource which, s64 value) { | 88 | bool KResourceLimit::Reserve(LimitableResource which, s64 value) { |
| 89 | return Reserve(which, value, core_timing->GetGlobalTimeNs().count() + DefaultTimeout); | 89 | return Reserve(which, value, m_core_timing->GetGlobalTimeNs().count() + DefaultTimeout); |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | bool KResourceLimit::Reserve(LimitableResource which, s64 value, s64 timeout) { | 92 | bool KResourceLimit::Reserve(LimitableResource which, s64 value, s64 timeout) { |
| 93 | ASSERT(value >= 0); | 93 | ASSERT(value >= 0); |
| 94 | const auto index = static_cast<std::size_t>(which); | 94 | const auto index = static_cast<std::size_t>(which); |
| 95 | KScopedLightLock lk(lock); | 95 | KScopedLightLock lk(m_lock); |
| 96 | 96 | ||
| 97 | ASSERT(current_hints[index] <= current_values[index]); | 97 | ASSERT(m_current_hints[index] <= m_current_values[index]); |
| 98 | if (current_hints[index] >= limit_values[index]) { | 98 | if (m_current_hints[index] >= m_limit_values[index]) { |
| 99 | return false; | 99 | return false; |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | // Loop until we reserve or run out of time. | 102 | // Loop until we reserve or run out of time. |
| 103 | while (true) { | 103 | while (true) { |
| 104 | ASSERT(current_values[index] <= limit_values[index]); | 104 | ASSERT(m_current_values[index] <= m_limit_values[index]); |
| 105 | ASSERT(current_hints[index] <= current_values[index]); | 105 | ASSERT(m_current_hints[index] <= m_current_values[index]); |
| 106 | 106 | ||
| 107 | // If we would overflow, don't allow to succeed. | 107 | // If we would overflow, don't allow to succeed. |
| 108 | if (Common::WrappingAdd(current_values[index], value) <= current_values[index]) { | 108 | if (Common::WrappingAdd(m_current_values[index], value) <= m_current_values[index]) { |
| 109 | break; | 109 | break; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | if (current_values[index] + value <= limit_values[index]) { | 112 | if (m_current_values[index] + value <= m_limit_values[index]) { |
| 113 | current_values[index] += value; | 113 | m_current_values[index] += value; |
| 114 | current_hints[index] += value; | 114 | m_current_hints[index] += value; |
| 115 | peak_values[index] = std::max(peak_values[index], current_values[index]); | 115 | m_peak_values[index] = std::max(m_peak_values[index], m_current_values[index]); |
| 116 | return true; | 116 | return true; |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | if (current_hints[index] + value <= limit_values[index] && | 119 | if (m_current_hints[index] + value <= m_limit_values[index] && |
| 120 | (timeout < 0 || core_timing->GetGlobalTimeNs().count() < timeout)) { | 120 | (timeout < 0 || m_core_timing->GetGlobalTimeNs().count() < timeout)) { |
| 121 | waiter_count++; | 121 | m_waiter_count++; |
| 122 | cond_var.Wait(&lock, timeout, false); | 122 | m_cond_var.Wait(&m_lock, timeout, false); |
| 123 | waiter_count--; | 123 | m_waiter_count--; |
| 124 | } else { | 124 | } else { |
| 125 | break; | 125 | break; |
| 126 | } | 126 | } |
| @@ -138,17 +138,17 @@ void KResourceLimit::Release(LimitableResource which, s64 value, s64 hint) { | |||
| 138 | ASSERT(hint >= 0); | 138 | ASSERT(hint >= 0); |
| 139 | 139 | ||
| 140 | const auto index = static_cast<std::size_t>(which); | 140 | const auto index = static_cast<std::size_t>(which); |
| 141 | KScopedLightLock lk(lock); | 141 | KScopedLightLock lk(m_lock); |
| 142 | ASSERT(current_values[index] <= limit_values[index]); | 142 | ASSERT(m_current_values[index] <= m_limit_values[index]); |
| 143 | ASSERT(current_hints[index] <= current_values[index]); | 143 | ASSERT(m_current_hints[index] <= m_current_values[index]); |
| 144 | ASSERT(value <= current_values[index]); | 144 | ASSERT(value <= m_current_values[index]); |
| 145 | ASSERT(hint <= current_hints[index]); | 145 | ASSERT(hint <= m_current_hints[index]); |
| 146 | 146 | ||
| 147 | current_values[index] -= value; | 147 | m_current_values[index] -= value; |
| 148 | current_hints[index] -= hint; | 148 | m_current_hints[index] -= hint; |
| 149 | 149 | ||
| 150 | if (waiter_count != 0) { | 150 | if (m_waiter_count != 0) { |
| 151 | cond_var.Broadcast(); | 151 | m_cond_var.Broadcast(); |
| 152 | } | 152 | } |
| 153 | } | 153 | } |
| 154 | 154 | ||
diff --git a/src/core/hle/kernel/k_resource_limit.h b/src/core/hle/kernel/k_resource_limit.h index bc4f48e15..15e69af56 100644 --- a/src/core/hle/kernel/k_resource_limit.h +++ b/src/core/hle/kernel/k_resource_limit.h | |||
| @@ -28,10 +28,10 @@ class KResourceLimit final | |||
| 28 | KERNEL_AUTOOBJECT_TRAITS(KResourceLimit, KAutoObject); | 28 | KERNEL_AUTOOBJECT_TRAITS(KResourceLimit, KAutoObject); |
| 29 | 29 | ||
| 30 | public: | 30 | public: |
| 31 | explicit KResourceLimit(KernelCore& kernel_); | 31 | explicit KResourceLimit(KernelCore& kernel); |
| 32 | ~KResourceLimit() override; | 32 | ~KResourceLimit() override; |
| 33 | 33 | ||
| 34 | void Initialize(const Core::Timing::CoreTiming* core_timing_); | 34 | void Initialize(const Core::Timing::CoreTiming* core_timing); |
| 35 | void Finalize() override; | 35 | void Finalize() override; |
| 36 | 36 | ||
| 37 | s64 GetLimitValue(LimitableResource which) const; | 37 | s64 GetLimitValue(LimitableResource which) const; |
| @@ -50,14 +50,14 @@ public: | |||
| 50 | 50 | ||
| 51 | private: | 51 | private: |
| 52 | using ResourceArray = std::array<s64, static_cast<std::size_t>(LimitableResource::Count)>; | 52 | using ResourceArray = std::array<s64, static_cast<std::size_t>(LimitableResource::Count)>; |
| 53 | ResourceArray limit_values{}; | 53 | ResourceArray m_limit_values{}; |
| 54 | ResourceArray current_values{}; | 54 | ResourceArray m_current_values{}; |
| 55 | ResourceArray current_hints{}; | 55 | ResourceArray m_current_hints{}; |
| 56 | ResourceArray peak_values{}; | 56 | ResourceArray m_peak_values{}; |
| 57 | mutable KLightLock lock; | 57 | mutable KLightLock m_lock; |
| 58 | s32 waiter_count{}; | 58 | s32 m_waiter_count{}; |
| 59 | KLightConditionVariable cond_var; | 59 | KLightConditionVariable m_cond_var; |
| 60 | const Core::Timing::CoreTiming* core_timing{}; | 60 | const Core::Timing::CoreTiming* m_core_timing{}; |
| 61 | }; | 61 | }; |
| 62 | 62 | ||
| 63 | KResourceLimit* CreateResourceLimitForProcess(Core::System& system, s64 physical_memory_size); | 63 | KResourceLimit* CreateResourceLimitForProcess(Core::System& system, s64 physical_memory_size); |