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