summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/kernel.h
diff options
context:
space:
mode:
authorGravatar Lioncash2018-08-28 12:30:33 -0400
committerGravatar Lioncash2018-08-28 22:31:51 -0400
commit0cbcd6ec9aeeafc298fe2e6e4ac10d68bb7267c5 (patch)
tree2d7bb143d490c3984bff6deda426b818bf27d552 /src/core/hle/kernel/kernel.h
parentMerge pull request #1193 from lioncash/priv (diff)
downloadyuzu-0cbcd6ec9aeeafc298fe2e6e4ac10d68bb7267c5.tar.gz
yuzu-0cbcd6ec9aeeafc298fe2e6e4ac10d68bb7267c5.tar.xz
yuzu-0cbcd6ec9aeeafc298fe2e6e4ac10d68bb7267c5.zip
kernel: Eliminate kernel global state
As means to pave the way for getting rid of global state within core, This eliminates kernel global state by removing all globals. Instead this introduces a KernelCore class which acts as a kernel instance. This instance lives in the System class, which keeps its lifetime contained to the lifetime of the System class. This also forces the kernel types to actually interact with the main kernel instance itself instead of having transient kernel state placed all over several translation units, keeping everything together. It also has a nice consequence of making dependencies much more explicit. This also makes our initialization a tad bit more correct. Previously we were creating a kernel process before the actual kernel was initialized, which doesn't really make much sense. The KernelCore class itself follows the PImpl idiom, which allows keeping all the implementation details sealed away from everything else, which forces the use of the exposed API and allows us to avoid any unnecessary inclusions within the main kernel header.
Diffstat (limited to 'src/core/hle/kernel/kernel.h')
-rw-r--r--src/core/hle/kernel/kernel.h89
1 files changed, 84 insertions, 5 deletions
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 131311472..089e959ac 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -4,14 +4,93 @@
4 4
5#pragma once 5#pragma once
6 6
7#include "common/common_types.h" 7#include "core/hle/kernel/object.h"
8
9template <typename T>
10class ResultVal;
11
12namespace CoreTiming {
13struct EventType;
14}
8 15
9namespace Kernel { 16namespace Kernel {
10 17
11/// Initialize the kernel with the specified system mode. 18class HandleTable;
12void Init(); 19class Process;
20class ResourceLimit;
21class Thread;
22class Timer;
23
24enum class ResourceLimitCategory : u8;
25
26/// Represents a single instance of the kernel.
27class KernelCore {
28public:
29 KernelCore();
30 ~KernelCore();
31
32 KernelCore(const KernelCore&) = delete;
33 KernelCore& operator=(const KernelCore&) = delete;
34
35 KernelCore(KernelCore&&) = delete;
36 KernelCore& operator=(KernelCore&&) = delete;
37
38 /// Resets the kernel to a clean slate for use.
39 void Initialize();
40
41 /// Clears all resources in use by the kernel instance.
42 void Shutdown();
43
44 /// Provides a reference to the handle table.
45 Kernel::HandleTable& HandleTable();
46
47 /// Provides a const reference to the handle table.
48 const Kernel::HandleTable& HandleTable() const;
49
50 /// Retrieves a shared pointer to a ResourceLimit identified by the given category.
51 SharedPtr<ResourceLimit> ResourceLimitForCategory(ResourceLimitCategory category) const;
52
53 /// Retrieves a shared pointer to a Thread instance within the thread wakeup handle table.
54 SharedPtr<Thread> RetrieveThreadFromWakeupCallbackHandleTable(Handle handle) const;
55
56 /// Retrieves a shared pointer to a Timer instance within the timer callback handle table.
57 SharedPtr<Timer> RetrieveTimerFromCallbackHandleTable(Handle handle) const;
58
59 /// Adds the given shared pointer to an internal list of active processes.
60 void AppendNewProcess(SharedPtr<Process> process);
61
62private:
63 friend class Object;
64 friend class Process;
65 friend class Thread;
66 friend class Timer;
67
68 /// Creates a new object ID, incrementing the internal object ID counter.
69 u32 CreateNewObjectID();
70
71 /// Creates a new process ID, incrementing the internal process ID counter;
72 u32 CreateNewProcessID();
73
74 /// Creates a new thread ID, incrementing the internal thread ID counter.
75 u32 CreateNewThreadID();
76
77 /// Creates a timer callback handle for the given timer.
78 ResultVal<Handle> CreateTimerCallbackHandle(const SharedPtr<Timer>& timer);
79
80 /// Retrieves the event type used for thread wakeup callbacks.
81 CoreTiming::EventType* ThreadWakeupCallbackEventType() const;
82
83 /// Retrieves the event type used for timer callbacks.
84 CoreTiming::EventType* TimerCallbackEventType() const;
85
86 /// Provides a reference to the thread wakeup callback handle table.
87 Kernel::HandleTable& ThreadWakeupCallbackHandleTable();
88
89 /// Provides a const reference to the thread wakeup callback handle table.
90 const Kernel::HandleTable& ThreadWakeupCallbackHandleTable() const;
13 91
14/// Shutdown the kernel 92 struct Impl;
15void Shutdown(); 93 std::unique_ptr<Impl> impl;
94};
16 95
17} // namespace Kernel 96} // namespace Kernel