diff options
author | bunnei <bunneidev@gmail.com> | 2021-02-03 23:53:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-03 23:53:25 +0100 |
commit | b0c97526633dffdf105f6d0a854ee2d02ae5a516 (patch) | |
tree | 9da902b04fb9424a3f1e32ee05b81327da521157 /src/core/hle/kernel/k_resource_limit.h | |
parent | Merge pull request #5842 from german77/userfix (diff) | |
parent | Simplify limitableresource names (diff) | |
download | yuzu-b0c97526633dffdf105f6d0a854ee2d02ae5a516.tar yuzu-b0c97526633dffdf105f6d0a854ee2d02ae5a516.tar.gz yuzu-b0c97526633dffdf105f6d0a854ee2d02ae5a516.tar.bz2 yuzu-b0c97526633dffdf105f6d0a854ee2d02ae5a516.tar.lz yuzu-b0c97526633dffdf105f6d0a854ee2d02ae5a516.tar.xz yuzu-b0c97526633dffdf105f6d0a854ee2d02ae5a516.tar.zst yuzu-b0c97526633dffdf105f6d0a854ee2d02ae5a516.zip |
Diffstat (limited to 'src/core/hle/kernel/k_resource_limit.h')
-rw-r--r-- | src/core/hle/kernel/k_resource_limit.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_resource_limit.h b/src/core/hle/kernel/k_resource_limit.h new file mode 100644 index 000000000..58ae456f1 --- /dev/null +++ b/src/core/hle/kernel/k_resource_limit.h @@ -0,0 +1,81 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +// This file references various implementation details from Atmosphere, an open-source firmware for +// the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX. + +#pragma once + +#include <array> +#include "common/common_types.h" +#include "core/hle/kernel/k_light_condition_variable.h" +#include "core/hle/kernel/k_light_lock.h" +#include "core/hle/kernel/object.h" + +union ResultCode; + +namespace Core { +class System; +} + +namespace Kernel { +class KernelCore; +enum class LimitableResource : u32 { + PhysicalMemory = 0, + Threads = 1, + Events = 2, + TransferMemory = 3, + Sessions = 4, + + Count, +}; + +constexpr bool IsValidResourceType(LimitableResource type) { + return type < LimitableResource::Count; +} + +class KResourceLimit final : public Object { +public: + explicit KResourceLimit(KernelCore& kernel, Core::System& system); + ~KResourceLimit(); + + s64 GetLimitValue(LimitableResource which) const; + s64 GetCurrentValue(LimitableResource which) const; + s64 GetPeakValue(LimitableResource which) const; + s64 GetFreeValue(LimitableResource which) const; + + ResultCode SetLimitValue(LimitableResource which, s64 value); + + bool Reserve(LimitableResource which, s64 value); + bool Reserve(LimitableResource which, s64 value, s64 timeout); + void Release(LimitableResource which, s64 value); + void Release(LimitableResource which, s64 value, s64 hint); + + std::string GetTypeName() const override { + return "KResourceLimit"; + } + std::string GetName() const override { + return GetTypeName(); + } + + static constexpr HandleType HANDLE_TYPE = HandleType::ResourceLimit; + HandleType GetHandleType() const override { + return HANDLE_TYPE; + } + + virtual void Finalize() override {} + +private: + using ResourceArray = std::array<s64, static_cast<std::size_t>(LimitableResource::Count)>; + ResourceArray limit_values{}; + ResourceArray current_values{}; + ResourceArray current_hints{}; + ResourceArray peak_values{}; + mutable KLightLock lock; + s32 waiter_count{}; + KLightConditionVariable cond_var; + KernelCore& kernel; + Core::System& system; +}; +} // namespace Kernel |