diff options
Diffstat (limited to 'src/core/core_timing.h')
| -rw-r--r-- | src/core/core_timing.h | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/src/core/core_timing.h b/src/core/core_timing.h index 3bb88c810..d50f4eb8a 100644 --- a/src/core/core_timing.h +++ b/src/core/core_timing.h | |||
| @@ -6,11 +6,12 @@ | |||
| 6 | 6 | ||
| 7 | #include <chrono> | 7 | #include <chrono> |
| 8 | #include <functional> | 8 | #include <functional> |
| 9 | #include <memory> | ||
| 9 | #include <mutex> | 10 | #include <mutex> |
| 10 | #include <optional> | 11 | #include <optional> |
| 11 | #include <string> | 12 | #include <string> |
| 12 | #include <unordered_map> | ||
| 13 | #include <vector> | 13 | #include <vector> |
| 14 | |||
| 14 | #include "common/common_types.h" | 15 | #include "common/common_types.h" |
| 15 | #include "common/threadsafe_queue.h" | 16 | #include "common/threadsafe_queue.h" |
| 16 | 17 | ||
| @@ -21,10 +22,13 @@ using TimedCallback = std::function<void(u64 userdata, s64 cycles_late)>; | |||
| 21 | 22 | ||
| 22 | /// Contains the characteristics of a particular event. | 23 | /// Contains the characteristics of a particular event. |
| 23 | struct EventType { | 24 | struct EventType { |
| 25 | EventType(TimedCallback&& callback, std::string&& name) | ||
| 26 | : callback{std::move(callback)}, name{std::move(name)} {} | ||
| 27 | |||
| 24 | /// The event's callback function. | 28 | /// The event's callback function. |
| 25 | TimedCallback callback; | 29 | TimedCallback callback; |
| 26 | /// A pointer to the name of the event. | 30 | /// A pointer to the name of the event. |
| 27 | const std::string* name; | 31 | const std::string name; |
| 28 | }; | 32 | }; |
| 29 | 33 | ||
| 30 | /** | 34 | /** |
| @@ -57,31 +61,17 @@ public: | |||
| 57 | /// Tears down all timing related functionality. | 61 | /// Tears down all timing related functionality. |
| 58 | void Shutdown(); | 62 | void Shutdown(); |
| 59 | 63 | ||
| 60 | /// Registers a core timing event with the given name and callback. | ||
| 61 | /// | ||
| 62 | /// @param name The name of the core timing event to register. | ||
| 63 | /// @param callback The callback to execute for the event. | ||
| 64 | /// | ||
| 65 | /// @returns An EventType instance representing the registered event. | ||
| 66 | /// | ||
| 67 | /// @pre The name of the event being registered must be unique among all | ||
| 68 | /// registered events. | ||
| 69 | /// | ||
| 70 | EventType* RegisterEvent(const std::string& name, TimedCallback callback); | ||
| 71 | |||
| 72 | /// Unregisters all registered events thus far. Note: not thread unsafe | ||
| 73 | void UnregisterAllEvents(); | ||
| 74 | |||
| 75 | /// After the first Advance, the slice lengths and the downcount will be reduced whenever an | 64 | /// After the first Advance, the slice lengths and the downcount will be reduced whenever an |
| 76 | /// event is scheduled earlier than the current values. | 65 | /// event is scheduled earlier than the current values. |
| 77 | /// | 66 | /// |
| 78 | /// Scheduling from a callback will not update the downcount until the Advance() completes. | 67 | /// Scheduling from a callback will not update the downcount until the Advance() completes. |
| 79 | void ScheduleEvent(s64 cycles_into_future, const EventType* event_type, u64 userdata = 0); | 68 | void ScheduleEvent(s64 cycles_into_future, const std::shared_ptr<EventType>& event_type, |
| 69 | u64 userdata = 0); | ||
| 80 | 70 | ||
| 81 | void UnscheduleEvent(const EventType* event_type, u64 userdata); | 71 | void UnscheduleEvent(const std::shared_ptr<EventType>& event_type, u64 userdata); |
| 82 | 72 | ||
| 83 | /// We only permit one event of each type in the queue at a time. | 73 | /// We only permit one event of each type in the queue at a time. |
| 84 | void RemoveEvent(const EventType* event_type); | 74 | void RemoveEvent(const std::shared_ptr<EventType>& event_type); |
| 85 | 75 | ||
| 86 | void ForceExceptionCheck(s64 cycles); | 76 | void ForceExceptionCheck(s64 cycles); |
| 87 | 77 | ||
| @@ -148,13 +138,18 @@ private: | |||
| 148 | std::vector<Event> event_queue; | 138 | std::vector<Event> event_queue; |
| 149 | u64 event_fifo_id = 0; | 139 | u64 event_fifo_id = 0; |
| 150 | 140 | ||
| 151 | // Stores each element separately as a linked list node so pointers to elements | 141 | std::shared_ptr<EventType> ev_lost; |
| 152 | // remain stable regardless of rehashes/resizing. | ||
| 153 | std::unordered_map<std::string, EventType> event_types; | ||
| 154 | |||
| 155 | EventType* ev_lost = nullptr; | ||
| 156 | 142 | ||
| 157 | std::mutex inner_mutex; | 143 | std::mutex inner_mutex; |
| 158 | }; | 144 | }; |
| 159 | 145 | ||
| 146 | /// Creates a core timing event with the given name and callback. | ||
| 147 | /// | ||
| 148 | /// @param name The name of the core timing event to create. | ||
| 149 | /// @param callback The callback to execute for the event. | ||
| 150 | /// | ||
| 151 | /// @returns An EventType instance representing the created event. | ||
| 152 | /// | ||
| 153 | std::shared_ptr<EventType> CreateEvent(std::string name, TimedCallback&& callback); | ||
| 154 | |||
| 160 | } // namespace Core::Timing | 155 | } // namespace Core::Timing |