Merge pull request #372 from lioncash/enum

resource_limit: Make ResourceTypes an enum class
This commit is contained in:
bunnei 2018-04-20 21:26:54 -04:00 committed by GitHub
commit 1723b4d8d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 38 deletions

View file

@ -34,57 +34,57 @@ SharedPtr<ResourceLimit> ResourceLimit::GetForCategory(ResourceLimitCategory cat
} }
} }
s32 ResourceLimit::GetCurrentResourceValue(u32 resource) const { s32 ResourceLimit::GetCurrentResourceValue(ResourceType resource) const {
switch (resource) { switch (resource) {
case COMMIT: case ResourceType::Commit:
return current_commit; return current_commit;
case THREAD: case ResourceType::Thread:
return current_threads; return current_threads;
case EVENT: case ResourceType::Event:
return current_events; return current_events;
case MUTEX: case ResourceType::Mutex:
return current_mutexes; return current_mutexes;
case SEMAPHORE: case ResourceType::Semaphore:
return current_semaphores; return current_semaphores;
case TIMER: case ResourceType::Timer:
return current_timers; return current_timers;
case SHARED_MEMORY: case ResourceType::SharedMemory:
return current_shared_mems; return current_shared_mems;
case ADDRESS_ARBITER: case ResourceType::AddressArbiter:
return current_address_arbiters; return current_address_arbiters;
case CPU_TIME: case ResourceType::CPUTime:
return current_cpu_time; return current_cpu_time;
default: default:
LOG_ERROR(Kernel, "Unknown resource type=%08X", resource); LOG_ERROR(Kernel, "Unknown resource type=%08X", static_cast<u32>(resource));
UNIMPLEMENTED(); UNIMPLEMENTED();
return 0; return 0;
} }
} }
u32 ResourceLimit::GetMaxResourceValue(u32 resource) const { u32 ResourceLimit::GetMaxResourceValue(ResourceType resource) const {
switch (resource) { switch (resource) {
case PRIORITY: case ResourceType::Priority:
return max_priority; return max_priority;
case COMMIT: case ResourceType::Commit:
return max_commit; return max_commit;
case THREAD: case ResourceType::Thread:
return max_threads; return max_threads;
case EVENT: case ResourceType::Event:
return max_events; return max_events;
case MUTEX: case ResourceType::Mutex:
return max_mutexes; return max_mutexes;
case SEMAPHORE: case ResourceType::Semaphore:
return max_semaphores; return max_semaphores;
case TIMER: case ResourceType::Timer:
return max_timers; return max_timers;
case SHARED_MEMORY: case ResourceType::SharedMemory:
return max_shared_mems; return max_shared_mems;
case ADDRESS_ARBITER: case ResourceType::AddressArbiter:
return max_address_arbiters; return max_address_arbiters;
case CPU_TIME: case ResourceType::CPUTime:
return max_cpu_time; return max_cpu_time;
default: default:
LOG_ERROR(Kernel, "Unknown resource type=%08X", resource); LOG_ERROR(Kernel, "Unknown resource type=%08X", static_cast<u32>(resource));
UNIMPLEMENTED(); UNIMPLEMENTED();
return 0; return 0;
} }

View file

@ -16,17 +16,17 @@ enum class ResourceLimitCategory : u8 {
OTHER = 3 OTHER = 3
}; };
enum ResourceTypes { enum class ResourceType {
PRIORITY = 0, Priority = 0,
COMMIT = 1, Commit = 1,
THREAD = 2, Thread = 2,
EVENT = 3, Event = 3,
MUTEX = 4, Mutex = 4,
SEMAPHORE = 5, Semaphore = 5,
TIMER = 6, Timer = 6,
SHARED_MEMORY = 7, SharedMemory = 7,
ADDRESS_ARBITER = 8, AddressArbiter = 8,
CPU_TIME = 9, CPUTime = 9,
}; };
class ResourceLimit final : public Object { class ResourceLimit final : public Object {
@ -60,14 +60,14 @@ public:
* @param resource Requested resource type * @param resource Requested resource type
* @returns The current value of the resource type * @returns The current value of the resource type
*/ */
s32 GetCurrentResourceValue(u32 resource) const; s32 GetCurrentResourceValue(ResourceType resource) const;
/** /**
* Gets the max value for the specified resource. * Gets the max value for the specified resource.
* @param resource Requested resource type * @param resource Requested resource type
* @returns The max value of the resource type * @returns The max value of the resource type
*/ */
u32 GetMaxResourceValue(u32 resource) const; u32 GetMaxResourceValue(ResourceType resource) const;
/// Name of resource limit object. /// Name of resource limit object.
std::string name; std::string name;

View file

@ -407,7 +407,7 @@ static ResultCode SetThreadPriority(Handle handle, u32 priority) {
// Note: The kernel uses the current process's resource limit instead of // Note: The kernel uses the current process's resource limit instead of
// the one from the thread owner's resource limit. // the one from the thread owner's resource limit.
SharedPtr<ResourceLimit>& resource_limit = Core::CurrentProcess()->resource_limit; SharedPtr<ResourceLimit>& resource_limit = Core::CurrentProcess()->resource_limit;
if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) { if (resource_limit->GetMaxResourceValue(ResourceType::Priority) > priority) {
return ERR_NOT_AUTHORIZED; return ERR_NOT_AUTHORIZED;
} }
@ -541,7 +541,7 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V
} }
SharedPtr<ResourceLimit>& resource_limit = Core::CurrentProcess()->resource_limit; SharedPtr<ResourceLimit>& resource_limit = Core::CurrentProcess()->resource_limit;
if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) { if (resource_limit->GetMaxResourceValue(ResourceType::Priority) > priority) {
return ERR_NOT_AUTHORIZED; return ERR_NOT_AUTHORIZED;
} }