2015-05-12 22:25:15 +02:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <cstring>
|
2017-05-30 01:45:42 +02:00
|
|
|
#include "common/assert.h"
|
2015-05-12 22:25:15 +02:00
|
|
|
#include "common/logging/log.h"
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "core/hle/kernel/resource_limit.h"
|
2015-05-12 22:25:15 +02:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2018-08-28 18:30:33 +02:00
|
|
|
ResourceLimit::ResourceLimit(KernelCore& kernel) : Object{kernel} {}
|
|
|
|
ResourceLimit::~ResourceLimit() = default;
|
2015-05-12 22:25:15 +02:00
|
|
|
|
2018-08-28 18:30:33 +02:00
|
|
|
SharedPtr<ResourceLimit> ResourceLimit::Create(KernelCore& kernel, std::string name) {
|
|
|
|
SharedPtr<ResourceLimit> resource_limit(new ResourceLimit(kernel));
|
2015-05-12 22:25:15 +02:00
|
|
|
|
|
|
|
resource_limit->name = std::move(name);
|
|
|
|
return resource_limit;
|
|
|
|
}
|
|
|
|
|
2018-04-21 01:35:02 +02:00
|
|
|
s32 ResourceLimit::GetCurrentResourceValue(ResourceType resource) const {
|
2015-05-12 22:25:15 +02:00
|
|
|
switch (resource) {
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::Commit:
|
2016-09-18 02:38:01 +02:00
|
|
|
return current_commit;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::Thread:
|
2016-09-18 02:38:01 +02:00
|
|
|
return current_threads;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::Event:
|
2016-09-18 02:38:01 +02:00
|
|
|
return current_events;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::Mutex:
|
2016-09-18 02:38:01 +02:00
|
|
|
return current_mutexes;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::Semaphore:
|
2016-09-18 02:38:01 +02:00
|
|
|
return current_semaphores;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::Timer:
|
2016-09-18 02:38:01 +02:00
|
|
|
return current_timers;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::SharedMemory:
|
2016-09-18 02:38:01 +02:00
|
|
|
return current_shared_mems;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::AddressArbiter:
|
2016-09-18 02:38:01 +02:00
|
|
|
return current_address_arbiters;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::CPUTime:
|
2016-09-18 02:38:01 +02:00
|
|
|
return current_cpu_time;
|
|
|
|
default:
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_ERROR(Kernel, "Unknown resource type={:08X}", static_cast<u32>(resource));
|
2016-09-18 02:38:01 +02:00
|
|
|
UNIMPLEMENTED();
|
|
|
|
return 0;
|
2015-05-12 22:25:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-21 01:35:02 +02:00
|
|
|
u32 ResourceLimit::GetMaxResourceValue(ResourceType resource) const {
|
2015-05-12 22:25:15 +02:00
|
|
|
switch (resource) {
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::Priority:
|
2017-01-11 18:08:10 +01:00
|
|
|
return max_priority;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::Commit:
|
2016-09-18 02:38:01 +02:00
|
|
|
return max_commit;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::Thread:
|
2016-09-18 02:38:01 +02:00
|
|
|
return max_threads;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::Event:
|
2016-09-18 02:38:01 +02:00
|
|
|
return max_events;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::Mutex:
|
2016-09-18 02:38:01 +02:00
|
|
|
return max_mutexes;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::Semaphore:
|
2016-09-18 02:38:01 +02:00
|
|
|
return max_semaphores;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::Timer:
|
2016-09-18 02:38:01 +02:00
|
|
|
return max_timers;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::SharedMemory:
|
2016-09-18 02:38:01 +02:00
|
|
|
return max_shared_mems;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::AddressArbiter:
|
2016-09-18 02:38:01 +02:00
|
|
|
return max_address_arbiters;
|
2018-04-21 01:35:02 +02:00
|
|
|
case ResourceType::CPUTime:
|
2016-09-18 02:38:01 +02:00
|
|
|
return max_cpu_time;
|
|
|
|
default:
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_ERROR(Kernel, "Unknown resource type={:08X}", static_cast<u32>(resource));
|
2016-09-18 02:38:01 +02:00
|
|
|
UNIMPLEMENTED();
|
|
|
|
return 0;
|
2015-05-12 22:25:15 +02:00
|
|
|
}
|
|
|
|
}
|
2018-01-20 08:48:02 +01:00
|
|
|
} // namespace Kernel
|