diff options
| author | 2019-06-15 10:12:41 -0400 | |
|---|---|---|
| committer | 2019-06-16 14:14:35 -0400 | |
| commit | 90792cdb6ea8f1676bd54309767209a4ec84a46f (patch) | |
| tree | eae330371459c0f9b71fcbf1c68e2fb01d19e294 /src/core/core_timing.h | |
| parent | Merge pull request #2578 from lioncash/cnmt (diff) | |
| download | yuzu-90792cdb6ea8f1676bd54309767209a4ec84a46f.tar.gz yuzu-90792cdb6ea8f1676bd54309767209a4ec84a46f.tar.xz yuzu-90792cdb6ea8f1676bd54309767209a4ec84a46f.zip | |
Core_Timing: Make core_timing threadsafe by default.
The old implementation had faulty Threadsafe methods where events could
be missing. This implementation unifies unsafe/safe methods and makes
core timing thread safe overall.
Diffstat (limited to 'src/core/core_timing.h')
| -rw-r--r-- | src/core/core_timing.h | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/src/core/core_timing.h b/src/core/core_timing.h index 9d2efde37..161c7007d 100644 --- a/src/core/core_timing.h +++ b/src/core/core_timing.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include <chrono> | 7 | #include <chrono> |
| 8 | #include <functional> | 8 | #include <functional> |
| 9 | #include <mutex> | ||
| 9 | #include <string> | 10 | #include <string> |
| 10 | #include <unordered_map> | 11 | #include <unordered_map> |
| 11 | #include <vector> | 12 | #include <vector> |
| @@ -67,7 +68,7 @@ public: | |||
| 67 | /// | 68 | /// |
| 68 | EventType* RegisterEvent(const std::string& name, TimedCallback callback); | 69 | EventType* RegisterEvent(const std::string& name, TimedCallback callback); |
| 69 | 70 | ||
| 70 | /// Unregisters all registered events thus far. | 71 | /// Unregisters all registered events thus far. Note: not thread unsafe |
| 71 | void UnregisterAllEvents(); | 72 | void UnregisterAllEvents(); |
| 72 | 73 | ||
| 73 | /// After the first Advance, the slice lengths and the downcount will be reduced whenever an | 74 | /// After the first Advance, the slice lengths and the downcount will be reduced whenever an |
| @@ -76,20 +77,10 @@ public: | |||
| 76 | /// Scheduling from a callback will not update the downcount until the Advance() completes. | 77 | /// Scheduling from a callback will not update the downcount until the Advance() completes. |
| 77 | void ScheduleEvent(s64 cycles_into_future, const EventType* event_type, u64 userdata = 0); | 78 | void ScheduleEvent(s64 cycles_into_future, const EventType* event_type, u64 userdata = 0); |
| 78 | 79 | ||
| 79 | /// This is to be called when outside of hle threads, such as the graphics thread, wants to | ||
| 80 | /// schedule things to be executed on the main thread. | ||
| 81 | /// | ||
| 82 | /// @note This doesn't change slice_length and thus events scheduled by this might be | ||
| 83 | /// called with a delay of up to MAX_SLICE_LENGTH | ||
| 84 | void ScheduleEventThreadsafe(s64 cycles_into_future, const EventType* event_type, | ||
| 85 | u64 userdata = 0); | ||
| 86 | |||
| 87 | void UnscheduleEvent(const EventType* event_type, u64 userdata); | 80 | void UnscheduleEvent(const EventType* event_type, u64 userdata); |
| 88 | void UnscheduleEventThreadsafe(const EventType* event_type, u64 userdata); | ||
| 89 | 81 | ||
| 90 | /// We only permit one event of each type in the queue at a time. | 82 | /// We only permit one event of each type in the queue at a time. |
| 91 | void RemoveEvent(const EventType* event_type); | 83 | void RemoveEvent(const EventType* event_type); |
| 92 | void RemoveNormalAndThreadsafeEvent(const EventType* event_type); | ||
| 93 | 84 | ||
| 94 | void ForceExceptionCheck(s64 cycles); | 85 | void ForceExceptionCheck(s64 cycles); |
| 95 | 86 | ||
| @@ -120,7 +111,6 @@ private: | |||
| 120 | 111 | ||
| 121 | /// Clear all pending events. This should ONLY be done on exit. | 112 | /// Clear all pending events. This should ONLY be done on exit. |
| 122 | void ClearPendingEvents(); | 113 | void ClearPendingEvents(); |
| 123 | void MoveEvents(); | ||
| 124 | 114 | ||
| 125 | s64 global_timer = 0; | 115 | s64 global_timer = 0; |
| 126 | s64 idled_cycles = 0; | 116 | s64 idled_cycles = 0; |
| @@ -143,14 +133,9 @@ private: | |||
| 143 | // remain stable regardless of rehashes/resizing. | 133 | // remain stable regardless of rehashes/resizing. |
| 144 | std::unordered_map<std::string, EventType> event_types; | 134 | std::unordered_map<std::string, EventType> event_types; |
| 145 | 135 | ||
| 146 | // The queue for storing the events from other threads threadsafe until they will be added | ||
| 147 | // to the event_queue by the emu thread | ||
| 148 | Common::MPSCQueue<Event> ts_queue; | ||
| 149 | |||
| 150 | // The queue for unscheduling the events from other threads threadsafe | ||
| 151 | Common::MPSCQueue<std::pair<const EventType*, u64>> unschedule_queue; | ||
| 152 | |||
| 153 | EventType* ev_lost = nullptr; | 136 | EventType* ev_lost = nullptr; |
| 137 | |||
| 138 | std::mutex inner_mutex; | ||
| 154 | }; | 139 | }; |
| 155 | 140 | ||
| 156 | } // namespace Core::Timing | 141 | } // namespace Core::Timing |