summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/resource_limit.cpp
blob: b253a680f70bf256539dd8e9fb4fab8164d6625c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2015 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include <cstring>
#include "common/assert.h"
#include "common/logging/log.h"
#include "core/hle/kernel/resource_limit.h"

namespace Kernel {

ResourceLimit::ResourceLimit(KernelCore& kernel) : Object{kernel} {}
ResourceLimit::~ResourceLimit() = default;

SharedPtr<ResourceLimit> ResourceLimit::Create(KernelCore& kernel, std::string name) {
    SharedPtr<ResourceLimit> resource_limit(new ResourceLimit(kernel));

    resource_limit->name = std::move(name);
    return resource_limit;
}

s32 ResourceLimit::GetCurrentResourceValue(ResourceType resource) const {
    switch (resource) {
    case ResourceType::Commit:
        return current_commit;
    case ResourceType::Thread:
        return current_threads;
    case ResourceType::Event:
        return current_events;
    case ResourceType::Mutex:
        return current_mutexes;
    case ResourceType::Semaphore:
        return current_semaphores;
    case ResourceType::Timer:
        return current_timers;
    case ResourceType::SharedMemory:
        return current_shared_mems;
    case ResourceType::AddressArbiter:
        return current_address_arbiters;
    case ResourceType::CPUTime:
        return current_cpu_time;
    default:
        LOG_ERROR(Kernel, "Unknown resource type={:08X}", static_cast<u32>(resource));
        UNIMPLEMENTED();
        return 0;
    }
}

u32 ResourceLimit::GetMaxResourceValue(ResourceType resource) const {
    switch (resource) {
    case ResourceType::Priority:
        return max_priority;
    case ResourceType::Commit:
        return max_commit;
    case ResourceType::Thread:
        return max_threads;
    case ResourceType::Event:
        return max_events;
    case ResourceType::Mutex:
        return max_mutexes;
    case ResourceType::Semaphore:
        return max_semaphores;
    case ResourceType::Timer:
        return max_timers;
    case ResourceType::SharedMemory:
        return max_shared_mems;
    case ResourceType::AddressArbiter:
        return max_address_arbiters;
    case ResourceType::CPUTime:
        return max_cpu_time;
    default:
        LOG_ERROR(Kernel, "Unknown resource type={:08X}", static_cast<u32>(resource));
        UNIMPLEMENTED();
        return 0;
    }
}
} // namespace Kernel