diff options
Diffstat (limited to 'src/core/hle/kernel/timer.cpp')
| -rw-r--r-- | src/core/hle/kernel/timer.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cpp index 794be060c..90e5e64b3 100644 --- a/src/core/hle/kernel/timer.cpp +++ b/src/core/hle/kernel/timer.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 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 <set> | ||
| 6 | |||
| 7 | #include "common/common.h" | 5 | #include "common/common.h" |
| 8 | 6 | ||
| 9 | #include "core/core_timing.h" | 7 | #include "core/core_timing.h" |
| @@ -15,6 +13,9 @@ namespace Kernel { | |||
| 15 | 13 | ||
| 16 | /// The event type of the generic timer callback event | 14 | /// The event type of the generic timer callback event |
| 17 | static int timer_callback_event_type = -1; | 15 | static int timer_callback_event_type = -1; |
| 16 | // TODO(yuriks): This can be removed if Timer objects are explicitly pooled in the future, allowing | ||
| 17 | // us to simply use a pool index or similar. | ||
| 18 | static Kernel::HandleTable timer_callback_handle_table; | ||
| 18 | 19 | ||
| 19 | ResultVal<SharedPtr<Timer>> Timer::Create(ResetType reset_type, std::string name) { | 20 | ResultVal<SharedPtr<Timer>> Timer::Create(ResetType reset_type, std::string name) { |
| 20 | SharedPtr<Timer> timer(new Timer); | 21 | SharedPtr<Timer> timer(new Timer); |
| @@ -26,6 +27,7 @@ ResultVal<SharedPtr<Timer>> Timer::Create(ResetType reset_type, std::string name | |||
| 26 | timer->name = std::move(name); | 27 | timer->name = std::move(name); |
| 27 | timer->initial_delay = 0; | 28 | timer->initial_delay = 0; |
| 28 | timer->interval_delay = 0; | 29 | timer->interval_delay = 0; |
| 30 | timer->callback_handle = timer_callback_handle_table.Create(timer).MoveFrom(); | ||
| 29 | return MakeResult<SharedPtr<Timer>>(timer); | 31 | return MakeResult<SharedPtr<Timer>>(timer); |
| 30 | } | 32 | } |
| 31 | 33 | ||
| @@ -45,13 +47,12 @@ void Timer::Set(s64 initial, s64 interval) { | |||
| 45 | interval_delay = interval; | 47 | interval_delay = interval; |
| 46 | 48 | ||
| 47 | u64 initial_microseconds = initial / 1000; | 49 | u64 initial_microseconds = initial / 1000; |
| 48 | // TODO(yuriks): Figure out a replacement for GetHandle here | 50 | CoreTiming::ScheduleEvent(usToCycles(initial_microseconds), |
| 49 | CoreTiming::ScheduleEvent(usToCycles(initial_microseconds), timer_callback_event_type, | 51 | timer_callback_event_type, callback_handle); |
| 50 | GetHandle()); | ||
| 51 | } | 52 | } |
| 52 | 53 | ||
| 53 | void Timer::Cancel() { | 54 | void Timer::Cancel() { |
| 54 | CoreTiming::UnscheduleEvent(timer_callback_event_type, GetHandle()); | 55 | CoreTiming::UnscheduleEvent(timer_callback_event_type, callback_handle); |
| 55 | } | 56 | } |
| 56 | 57 | ||
| 57 | void Timer::Clear() { | 58 | void Timer::Clear() { |
| @@ -60,7 +61,7 @@ void Timer::Clear() { | |||
| 60 | 61 | ||
| 61 | /// The timer callback event, called when a timer is fired | 62 | /// The timer callback event, called when a timer is fired |
| 62 | static void TimerCallback(u64 timer_handle, int cycles_late) { | 63 | static void TimerCallback(u64 timer_handle, int cycles_late) { |
| 63 | SharedPtr<Timer> timer = Kernel::g_handle_table.Get<Timer>(timer_handle); | 64 | SharedPtr<Timer> timer = timer_callback_handle_table.Get<Timer>(timer_handle); |
| 64 | 65 | ||
| 65 | if (timer == nullptr) { | 66 | if (timer == nullptr) { |
| 66 | LOG_CRITICAL(Kernel, "Callback fired for invalid timer %08X", timer_handle); | 67 | LOG_CRITICAL(Kernel, "Callback fired for invalid timer %08X", timer_handle); |