summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/timer.cpp
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/timer.cpp
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/timer.cpp')
-rw-r--r--src/core/hle/kernel/timer.cpp45
1 files changed, 10 insertions, 35 deletions
diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cpp
index 282360745..6957b16e0 100644
--- a/src/core/hle/kernel/timer.cpp
+++ b/src/core/hle/kernel/timer.cpp
@@ -2,36 +2,31 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <cinttypes>
6#include "common/assert.h" 5#include "common/assert.h"
7#include "common/logging/log.h" 6#include "common/logging/log.h"
7#include "core/core.h"
8#include "core/core_timing.h" 8#include "core/core_timing.h"
9#include "core/core_timing_util.h" 9#include "core/core_timing_util.h"
10#include "core/hle/kernel/handle_table.h" 10#include "core/hle/kernel/handle_table.h"
11#include "core/hle/kernel/kernel.h"
11#include "core/hle/kernel/object.h" 12#include "core/hle/kernel/object.h"
12#include "core/hle/kernel/thread.h" 13#include "core/hle/kernel/thread.h"
13#include "core/hle/kernel/timer.h" 14#include "core/hle/kernel/timer.h"
14 15
15namespace Kernel { 16namespace Kernel {
16 17
17/// The event type of the generic timer callback event 18Timer::Timer(KernelCore& kernel) : WaitObject{kernel} {}
18static CoreTiming::EventType* timer_callback_event_type = nullptr; 19Timer::~Timer() = default;
19// TODO(yuriks): This can be removed if Timer objects are explicitly pooled in the future, allowing
20// us to simply use a pool index or similar.
21static Kernel::HandleTable timer_callback_handle_table;
22 20
23Timer::Timer() {} 21SharedPtr<Timer> Timer::Create(KernelCore& kernel, ResetType reset_type, std::string name) {
24Timer::~Timer() {} 22 SharedPtr<Timer> timer(new Timer(kernel));
25
26SharedPtr<Timer> Timer::Create(ResetType reset_type, std::string name) {
27 SharedPtr<Timer> timer(new Timer);
28 23
29 timer->reset_type = reset_type; 24 timer->reset_type = reset_type;
30 timer->signaled = false; 25 timer->signaled = false;
31 timer->name = std::move(name); 26 timer->name = std::move(name);
32 timer->initial_delay = 0; 27 timer->initial_delay = 0;
33 timer->interval_delay = 0; 28 timer->interval_delay = 0;
34 timer->callback_handle = timer_callback_handle_table.Create(timer).Unwrap(); 29 timer->callback_handle = kernel.CreateTimerCallbackHandle(timer).Unwrap();
35 30
36 return timer; 31 return timer;
37} 32}
@@ -58,13 +53,13 @@ void Timer::Set(s64 initial, s64 interval) {
58 // Immediately invoke the callback 53 // Immediately invoke the callback
59 Signal(0); 54 Signal(0);
60 } else { 55 } else {
61 CoreTiming::ScheduleEvent(CoreTiming::nsToCycles(initial), timer_callback_event_type, 56 CoreTiming::ScheduleEvent(CoreTiming::nsToCycles(initial), kernel.TimerCallbackEventType(),
62 callback_handle); 57 callback_handle);
63 } 58 }
64} 59}
65 60
66void Timer::Cancel() { 61void Timer::Cancel() {
67 CoreTiming::UnscheduleEvent(timer_callback_event_type, callback_handle); 62 CoreTiming::UnscheduleEvent(kernel.TimerCallbackEventType(), callback_handle);
68} 63}
69 64
70void Timer::Clear() { 65void Timer::Clear() {
@@ -89,28 +84,8 @@ void Timer::Signal(int cycles_late) {
89 if (interval_delay != 0) { 84 if (interval_delay != 0) {
90 // Reschedule the timer with the interval delay 85 // Reschedule the timer with the interval delay
91 CoreTiming::ScheduleEvent(CoreTiming::nsToCycles(interval_delay) - cycles_late, 86 CoreTiming::ScheduleEvent(CoreTiming::nsToCycles(interval_delay) - cycles_late,
92 timer_callback_event_type, callback_handle); 87 kernel.TimerCallbackEventType(), callback_handle);
93 } 88 }
94} 89}
95 90
96/// The timer callback event, called when a timer is fired
97static void TimerCallback(u64 timer_handle, int cycles_late) {
98 SharedPtr<Timer> timer =
99 timer_callback_handle_table.Get<Timer>(static_cast<Handle>(timer_handle));
100
101 if (timer == nullptr) {
102 LOG_CRITICAL(Kernel, "Callback fired for invalid timer {:016X}", timer_handle);
103 return;
104 }
105
106 timer->Signal(cycles_late);
107}
108
109void TimersInit() {
110 timer_callback_handle_table.Clear();
111 timer_callback_event_type = CoreTiming::RegisterEvent("TimerCallback", TimerCallback);
112}
113
114void TimersShutdown() {}
115
116} // namespace Kernel 91} // namespace Kernel