diff options
Diffstat (limited to 'src/core/hle/kernel/timer.cpp')
| -rw-r--r-- | src/core/hle/kernel/timer.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cpp index 503a5d2ce..4352fc99c 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,18 +13,24 @@ 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; | ||
| 19 | |||
| 20 | Timer::Timer() {} | ||
| 21 | Timer::~Timer() {} | ||
| 18 | 22 | ||
| 19 | ResultVal<SharedPtr<Timer>> Timer::Create(ResetType reset_type, std::string name) { | 23 | SharedPtr<Timer> Timer::Create(ResetType reset_type, std::string name) { |
| 20 | SharedPtr<Timer> timer(new Timer); | 24 | SharedPtr<Timer> timer(new Timer); |
| 21 | // TOOD(yuriks): Don't create Handle (see Thread::Create()) | ||
| 22 | CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(timer)); | ||
| 23 | 25 | ||
| 24 | timer->reset_type = reset_type; | 26 | timer->reset_type = reset_type; |
| 25 | timer->signaled = false; | 27 | timer->signaled = false; |
| 26 | timer->name = std::move(name); | 28 | timer->name = std::move(name); |
| 27 | timer->initial_delay = 0; | 29 | timer->initial_delay = 0; |
| 28 | timer->interval_delay = 0; | 30 | timer->interval_delay = 0; |
| 29 | return MakeResult<SharedPtr<Timer>>(timer); | 31 | timer->callback_handle = timer_callback_handle_table.Create(timer).MoveFrom(); |
| 32 | |||
| 33 | return timer; | ||
| 30 | } | 34 | } |
| 31 | 35 | ||
| 32 | bool Timer::ShouldWait() { | 36 | bool Timer::ShouldWait() { |
| @@ -38,17 +42,19 @@ void Timer::Acquire() { | |||
| 38 | } | 42 | } |
| 39 | 43 | ||
| 40 | void Timer::Set(s64 initial, s64 interval) { | 44 | void Timer::Set(s64 initial, s64 interval) { |
| 45 | // Ensure we get rid of any previous scheduled event | ||
| 46 | Cancel(); | ||
| 47 | |||
| 41 | initial_delay = initial; | 48 | initial_delay = initial; |
| 42 | interval_delay = interval; | 49 | interval_delay = interval; |
| 43 | 50 | ||
| 44 | u64 initial_microseconds = initial / 1000; | 51 | u64 initial_microseconds = initial / 1000; |
| 45 | // TODO(yuriks): Figure out a replacement for GetHandle here | 52 | CoreTiming::ScheduleEvent(usToCycles(initial_microseconds), |
| 46 | CoreTiming::ScheduleEvent(usToCycles(initial_microseconds), timer_callback_event_type, | 53 | timer_callback_event_type, callback_handle); |
| 47 | GetHandle()); | ||
| 48 | } | 54 | } |
| 49 | 55 | ||
| 50 | void Timer::Cancel() { | 56 | void Timer::Cancel() { |
| 51 | CoreTiming::UnscheduleEvent(timer_callback_event_type, GetHandle()); | 57 | CoreTiming::UnscheduleEvent(timer_callback_event_type, callback_handle); |
| 52 | } | 58 | } |
| 53 | 59 | ||
| 54 | void Timer::Clear() { | 60 | void Timer::Clear() { |
| @@ -57,7 +63,7 @@ void Timer::Clear() { | |||
| 57 | 63 | ||
| 58 | /// The timer callback event, called when a timer is fired | 64 | /// The timer callback event, called when a timer is fired |
| 59 | static void TimerCallback(u64 timer_handle, int cycles_late) { | 65 | static void TimerCallback(u64 timer_handle, int cycles_late) { |
| 60 | SharedPtr<Timer> timer = Kernel::g_handle_table.Get<Timer>(timer_handle); | 66 | SharedPtr<Timer> timer = timer_callback_handle_table.Get<Timer>(timer_handle); |
| 61 | 67 | ||
| 62 | if (timer == nullptr) { | 68 | if (timer == nullptr) { |
| 63 | LOG_CRITICAL(Kernel, "Callback fired for invalid timer %08X", timer_handle); | 69 | LOG_CRITICAL(Kernel, "Callback fired for invalid timer %08X", timer_handle); |