diff options
| author | 2015-01-31 14:23:09 -0200 | |
|---|---|---|
| committer | 2015-02-02 15:37:03 -0200 | |
| commit | a9b86db3cfec5ce907051d6730ffd98c0fd03876 (patch) | |
| tree | 791877de9d2a746a5a73e32a3bb3110670cff91a /src | |
| parent | Kernel: Remove previous scheduled event when a Timer is re-Set (diff) | |
| download | yuzu-a9b86db3cfec5ce907051d6730ffd98c0fd03876.tar.gz yuzu-a9b86db3cfec5ce907051d6730ffd98c0fd03876.tar.xz yuzu-a9b86db3cfec5ce907051d6730ffd98c0fd03876.zip | |
Kernel: Use separate Handle tables for CoreTiming userdata
This is to support the removal of GetHandle soon
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 22 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 3 | ||||
| -rw-r--r-- | src/core/hle/kernel/timer.cpp | 15 | ||||
| -rw-r--r-- | src/core/hle/kernel/timer.h | 3 |
4 files changed, 25 insertions, 18 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 1ea5589cb..72a14bfac 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <list> | 6 | #include <list> |
| 7 | #include <map> | ||
| 8 | #include <vector> | 7 | #include <vector> |
| 9 | 8 | ||
| 10 | #include "common/common.h" | 9 | #include "common/common.h" |
| @@ -228,13 +227,15 @@ void WaitCurrentThread_ArbitrateAddress(VAddr wait_address) { | |||
| 228 | 227 | ||
| 229 | /// Event type for the thread wake up event | 228 | /// Event type for the thread wake up event |
| 230 | static int ThreadWakeupEventType = -1; | 229 | static int ThreadWakeupEventType = -1; |
| 230 | // TODO(yuriks): This can be removed if Thread objects are explicitly pooled in the future, allowing | ||
| 231 | // us to simply use a pool index or similar. | ||
| 232 | static Kernel::HandleTable wakeup_callback_handle_table; | ||
| 231 | 233 | ||
| 232 | /// Callback that will wake up the thread it was scheduled for | 234 | /// Callback that will wake up the thread it was scheduled for |
| 233 | static void ThreadWakeupCallback(u64 parameter, int cycles_late) { | 235 | static void ThreadWakeupCallback(u64 thread_handle, int cycles_late) { |
| 234 | Handle handle = static_cast<Handle>(parameter); | 236 | SharedPtr<Thread> thread = wakeup_callback_handle_table.Get<Thread>((Handle)thread_handle); |
| 235 | SharedPtr<Thread> thread = Kernel::g_handle_table.Get<Thread>(handle); | ||
| 236 | if (thread == nullptr) { | 237 | if (thread == nullptr) { |
| 237 | LOG_ERROR(Kernel, "Thread doesn't exist %u", handle); | 238 | LOG_CRITICAL(Kernel, "Callback fired for invalid thread %08X", thread_handle); |
| 238 | return; | 239 | return; |
| 239 | } | 240 | } |
| 240 | 241 | ||
| @@ -254,7 +255,7 @@ void Thread::WakeAfterDelay(s64 nanoseconds) { | |||
| 254 | return; | 255 | return; |
| 255 | 256 | ||
| 256 | u64 microseconds = nanoseconds / 1000; | 257 | u64 microseconds = nanoseconds / 1000; |
| 257 | CoreTiming::ScheduleEvent(usToCycles(microseconds), ThreadWakeupEventType, GetHandle()); | 258 | CoreTiming::ScheduleEvent(usToCycles(microseconds), ThreadWakeupEventType, callback_handle); |
| 258 | } | 259 | } |
| 259 | 260 | ||
| 260 | void Thread::ReleaseWaitObject(WaitObject* wait_object) { | 261 | void Thread::ReleaseWaitObject(WaitObject* wait_object) { |
| @@ -301,7 +302,7 @@ void Thread::ReleaseWaitObject(WaitObject* wait_object) { | |||
| 301 | 302 | ||
| 302 | void Thread::ResumeFromWait() { | 303 | void Thread::ResumeFromWait() { |
| 303 | // Cancel any outstanding wakeup events | 304 | // Cancel any outstanding wakeup events |
| 304 | CoreTiming::UnscheduleEvent(ThreadWakeupEventType, GetHandle()); | 305 | CoreTiming::UnscheduleEvent(ThreadWakeupEventType, callback_handle); |
| 305 | 306 | ||
| 306 | status &= ~THREADSTATUS_WAIT; | 307 | status &= ~THREADSTATUS_WAIT; |
| 307 | 308 | ||
| @@ -384,6 +385,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, | |||
| 384 | thread->wait_objects.clear(); | 385 | thread->wait_objects.clear(); |
| 385 | thread->wait_address = 0; | 386 | thread->wait_address = 0; |
| 386 | thread->name = std::move(name); | 387 | thread->name = std::move(name); |
| 388 | thread->callback_handle = wakeup_callback_handle_table.Create(thread).MoveFrom(); | ||
| 387 | 389 | ||
| 388 | ResetThread(thread.get(), arg, 0); | 390 | ResetThread(thread.get(), arg, 0); |
| 389 | CallThread(thread.get()); | 391 | CallThread(thread.get()); |
| @@ -419,10 +421,8 @@ void Thread::SetPriority(s32 priority) { | |||
| 419 | 421 | ||
| 420 | SharedPtr<Thread> SetupIdleThread() { | 422 | SharedPtr<Thread> SetupIdleThread() { |
| 421 | // We need to pass a few valid values to get around parameter checking in Thread::Create. | 423 | // We need to pass a few valid values to get around parameter checking in Thread::Create. |
| 422 | auto thread_res = Thread::Create("idle", Memory::KERNEL_MEMORY_VADDR, THREADPRIO_LOWEST, 0, | 424 | auto thread = Thread::Create("idle", Memory::KERNEL_MEMORY_VADDR, THREADPRIO_LOWEST, 0, |
| 423 | THREADPROCESSORID_0, 0, Kernel::DEFAULT_STACK_SIZE); | 425 | THREADPROCESSORID_0, 0, Kernel::DEFAULT_STACK_SIZE).MoveFrom(); |
| 424 | _dbg_assert_(Kernel, thread_res.Succeeded()); | ||
| 425 | SharedPtr<Thread> thread = std::move(*thread_res); | ||
| 426 | 426 | ||
| 427 | thread->idle = true; | 427 | thread->idle = true; |
| 428 | CallThread(thread.get()); | 428 | CallThread(thread.get()); |
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index cba074e07..9a4a00fe8 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -122,6 +122,9 @@ public: | |||
| 122 | 122 | ||
| 123 | private: | 123 | private: |
| 124 | Thread() = default; | 124 | Thread() = default; |
| 125 | |||
| 126 | /// Handle used as userdata to reference this object when inserting into the CoreTiming queue. | ||
| 127 | Handle callback_handle; | ||
| 125 | }; | 128 | }; |
| 126 | 129 | ||
| 127 | /// Sets up the primary application thread | 130 | /// Sets up the primary application thread |
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); |
diff --git a/src/core/hle/kernel/timer.h b/src/core/hle/kernel/timer.h index c45e79954..f72b8b31b 100644 --- a/src/core/hle/kernel/timer.h +++ b/src/core/hle/kernel/timer.h | |||
| @@ -50,6 +50,9 @@ public: | |||
| 50 | 50 | ||
| 51 | private: | 51 | private: |
| 52 | Timer() = default; | 52 | Timer() = default; |
| 53 | |||
| 54 | /// Handle used as userdata to reference this object when inserting into the CoreTiming queue. | ||
| 55 | Handle callback_handle; | ||
| 53 | }; | 56 | }; |
| 54 | 57 | ||
| 55 | /// Initializes the required variables for timers | 58 | /// Initializes the required variables for timers |