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