summaryrefslogtreecommitdiff
path: root/src/core/core_timing.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2020-07-27 19:00:41 -0400
committerGravatar Lioncash2020-07-27 21:21:01 -0400
commita7af349daee85237384dba07533c9a407cf15592 (patch)
treee337a6e823960cc6b2a7d05c7e33e80cc51a4581 /src/core/core_timing.cpp
parentMerge pull request #4419 from lioncash/initializer (diff)
downloadyuzu-a7af349daee85237384dba07533c9a407cf15592.tar.gz
yuzu-a7af349daee85237384dba07533c9a407cf15592.tar.xz
yuzu-a7af349daee85237384dba07533c9a407cf15592.zip
core_timing: Make use of uintptr_t to represent user_data
Makes the interface future-proofed for supporting other platforms in the event we ever support platforms with differing pointer sizes. This way, we have a type in place that is always guaranteed to be able to represent a pointer exactly.
Diffstat (limited to 'src/core/core_timing.cpp')
-rw-r--r--src/core/core_timing.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index b5feb3f24..71af26ec5 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -23,7 +23,7 @@ std::shared_ptr<EventType> CreateEvent(std::string name, TimedCallback&& callbac
23struct CoreTiming::Event { 23struct CoreTiming::Event {
24 u64 time; 24 u64 time;
25 u64 fifo_order; 25 u64 fifo_order;
26 u64 userdata; 26 std::uintptr_t user_data;
27 std::weak_ptr<EventType> type; 27 std::weak_ptr<EventType> type;
28 28
29 // Sort by time, unless the times are the same, in which case sort by 29 // Sort by time, unless the times are the same, in which case sort by
@@ -58,7 +58,7 @@ void CoreTiming::Initialize(std::function<void()>&& on_thread_init_) {
58 event_fifo_id = 0; 58 event_fifo_id = 0;
59 shutting_down = false; 59 shutting_down = false;
60 ticks = 0; 60 ticks = 0;
61 const auto empty_timed_callback = [](u64, std::chrono::nanoseconds) {}; 61 const auto empty_timed_callback = [](std::uintptr_t, std::chrono::nanoseconds) {};
62 ev_lost = CreateEvent("_lost_event", empty_timed_callback); 62 ev_lost = CreateEvent("_lost_event", empty_timed_callback);
63 if (is_multicore) { 63 if (is_multicore) {
64 timer_thread = std::make_unique<std::thread>(ThreadEntry, std::ref(*this)); 64 timer_thread = std::make_unique<std::thread>(ThreadEntry, std::ref(*this));
@@ -107,22 +107,24 @@ bool CoreTiming::HasPendingEvents() const {
107} 107}
108 108
109void CoreTiming::ScheduleEvent(std::chrono::nanoseconds ns_into_future, 109void CoreTiming::ScheduleEvent(std::chrono::nanoseconds ns_into_future,
110 const std::shared_ptr<EventType>& event_type, u64 userdata) { 110 const std::shared_ptr<EventType>& event_type,
111 std::uintptr_t user_data) {
111 { 112 {
112 std::scoped_lock scope{basic_lock}; 113 std::scoped_lock scope{basic_lock};
113 const u64 timeout = static_cast<u64>((GetGlobalTimeNs() + ns_into_future).count()); 114 const u64 timeout = static_cast<u64>((GetGlobalTimeNs() + ns_into_future).count());
114 115
115 event_queue.emplace_back(Event{timeout, event_fifo_id++, userdata, event_type}); 116 event_queue.emplace_back(Event{timeout, event_fifo_id++, user_data, event_type});
116 117
117 std::push_heap(event_queue.begin(), event_queue.end(), std::greater<>()); 118 std::push_heap(event_queue.begin(), event_queue.end(), std::greater<>());
118 } 119 }
119 event.Set(); 120 event.Set();
120} 121}
121 122
122void CoreTiming::UnscheduleEvent(const std::shared_ptr<EventType>& event_type, u64 userdata) { 123void CoreTiming::UnscheduleEvent(const std::shared_ptr<EventType>& event_type,
124 std::uintptr_t user_data) {
123 std::scoped_lock scope{basic_lock}; 125 std::scoped_lock scope{basic_lock};
124 const auto itr = std::remove_if(event_queue.begin(), event_queue.end(), [&](const Event& e) { 126 const auto itr = std::remove_if(event_queue.begin(), event_queue.end(), [&](const Event& e) {
125 return e.type.lock().get() == event_type.get() && e.userdata == userdata; 127 return e.type.lock().get() == event_type.get() && e.user_data == user_data;
126 }); 128 });
127 129
128 // Removing random items breaks the invariant so we have to re-establish it. 130 // Removing random items breaks the invariant so we have to re-establish it.
@@ -197,7 +199,7 @@ std::optional<s64> CoreTiming::Advance() {
197 199
198 if (const auto event_type{evt.type.lock()}) { 200 if (const auto event_type{evt.type.lock()}) {
199 event_type->callback( 201 event_type->callback(
200 evt.userdata, std::chrono::nanoseconds{static_cast<s64>(global_timer - evt.time)}); 202 evt.user_data, std::chrono::nanoseconds{static_cast<s64>(global_timer - evt.time)});
201 } 203 }
202 204
203 basic_lock.lock(); 205 basic_lock.lock();