summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2020-02-10 14:45:08 -0400
committerGravatar Fernando Sahmkow2020-06-18 16:29:21 -0400
commit1f7dd36499786d373b143a4437d4c32e077a32aa (patch)
tree26d21b113d85c6630f3ff67f7affc7c1b6f508a5 /src
parentCommon: Make MinGW build use Windows Fibers instead of fcontext_t (diff)
downloadyuzu-1f7dd36499786d373b143a4437d4c32e077a32aa.tar.gz
yuzu-1f7dd36499786d373b143a4437d4c32e077a32aa.tar.xz
yuzu-1f7dd36499786d373b143a4437d4c32e077a32aa.zip
Common/Tests: Address Feedback
Diffstat (limited to 'src')
-rw-r--r--src/common/fiber.cpp5
-rw-r--r--src/common/fiber.h8
-rw-r--r--src/common/spin_lock.cpp3
-rw-r--r--src/core/core_timing_util.cpp14
-rw-r--r--src/core/core_timing_util.h2
-rw-r--r--src/core/host_timing.cpp4
-rw-r--r--src/core/host_timing.h6
-rw-r--r--src/tests/common/fibers.cpp20
-rw-r--r--src/tests/core/host_timing.cpp28
9 files changed, 51 insertions, 39 deletions
diff --git a/src/common/fiber.cpp b/src/common/fiber.cpp
index 050c93acb..1220eddf0 100644
--- a/src/common/fiber.cpp
+++ b/src/common/fiber.cpp
@@ -32,13 +32,12 @@ void __stdcall Fiber::FiberStartFunc(void* fiber_parameter) {
32} 32}
33 33
34Fiber::Fiber(std::function<void(void*)>&& entry_point_func, void* start_parameter) 34Fiber::Fiber(std::function<void(void*)>&& entry_point_func, void* start_parameter)
35 : guard{}, entry_point{std::move(entry_point_func)}, start_parameter{start_parameter}, 35 : entry_point{std::move(entry_point_func)}, start_parameter{start_parameter} {
36 previous_fiber{} {
37 impl = std::make_unique<FiberImpl>(); 36 impl = std::make_unique<FiberImpl>();
38 impl->handle = CreateFiber(0, &FiberStartFunc, this); 37 impl->handle = CreateFiber(0, &FiberStartFunc, this);
39} 38}
40 39
41Fiber::Fiber() : guard{}, entry_point{}, start_parameter{}, previous_fiber{} { 40Fiber::Fiber() {
42 impl = std::make_unique<FiberImpl>(); 41 impl = std::make_unique<FiberImpl>();
43} 42}
44 43
diff --git a/src/common/fiber.h b/src/common/fiber.h
index 598fe7daa..7e3b130a4 100644
--- a/src/common/fiber.h
+++ b/src/common/fiber.h
@@ -67,10 +67,10 @@ private:
67 67
68 struct FiberImpl; 68 struct FiberImpl;
69 69
70 SpinLock guard; 70 SpinLock guard{};
71 std::function<void(void*)> entry_point; 71 std::function<void(void*)> entry_point{};
72 void* start_parameter; 72 void* start_parameter{};
73 std::shared_ptr<Fiber> previous_fiber; 73 std::shared_ptr<Fiber> previous_fiber{};
74 std::unique_ptr<FiberImpl> impl; 74 std::unique_ptr<FiberImpl> impl;
75 bool is_thread_fiber{}; 75 bool is_thread_fiber{};
76}; 76};
diff --git a/src/common/spin_lock.cpp b/src/common/spin_lock.cpp
index 82a1d39ff..c7b46aac6 100644
--- a/src/common/spin_lock.cpp
+++ b/src/common/spin_lock.cpp
@@ -35,8 +35,9 @@ void thread_pause() {
35namespace Common { 35namespace Common {
36 36
37void SpinLock::lock() { 37void SpinLock::lock() {
38 while (lck.test_and_set(std::memory_order_acquire)) 38 while (lck.test_and_set(std::memory_order_acquire)) {
39 thread_pause(); 39 thread_pause();
40 }
40} 41}
41 42
42void SpinLock::unlock() { 43void SpinLock::unlock() {
diff --git a/src/core/core_timing_util.cpp b/src/core/core_timing_util.cpp
index f42666b4d..be34b26fe 100644
--- a/src/core/core_timing_util.cpp
+++ b/src/core/core_timing_util.cpp
@@ -49,9 +49,19 @@ s64 nsToCycles(std::chrono::nanoseconds ns) {
49 return (Hardware::BASE_CLOCK_RATE * ns.count()) / 1000000000; 49 return (Hardware::BASE_CLOCK_RATE * ns.count()) / 1000000000;
50} 50}
51 51
52u64 msToClockCycles(std::chrono::milliseconds ns) {
53 const u128 temp = Common::Multiply64Into128(ns.count(), Hardware::CNTFREQ);
54 return Common::Divide128On32(temp, 1000).first;
55}
56
57u64 usToClockCycles(std::chrono::microseconds ns) {
58 const u128 temp = Common::Multiply64Into128(ns.count(), Hardware::CNTFREQ);
59 return Common::Divide128On32(temp, 1000000).first;
60}
61
52u64 nsToClockCycles(std::chrono::nanoseconds ns) { 62u64 nsToClockCycles(std::chrono::nanoseconds ns) {
53 const u128 temporal = Common::Multiply64Into128(ns.count(), CNTFREQ); 63 const u128 temp = Common::Multiply64Into128(ns.count(), Hardware::CNTFREQ);
54 return Common::Divide128On32(temporal, 1000000000).first; 64 return Common::Divide128On32(temp, 1000000000).first;
55} 65}
56 66
57u64 CpuCyclesToClockCycles(u64 ticks) { 67u64 CpuCyclesToClockCycles(u64 ticks) {
diff --git a/src/core/core_timing_util.h b/src/core/core_timing_util.h
index 65fb7368b..b3c58447d 100644
--- a/src/core/core_timing_util.h
+++ b/src/core/core_timing_util.h
@@ -13,6 +13,8 @@ namespace Core::Timing {
13s64 msToCycles(std::chrono::milliseconds ms); 13s64 msToCycles(std::chrono::milliseconds ms);
14s64 usToCycles(std::chrono::microseconds us); 14s64 usToCycles(std::chrono::microseconds us);
15s64 nsToCycles(std::chrono::nanoseconds ns); 15s64 nsToCycles(std::chrono::nanoseconds ns);
16u64 msToClockCycles(std::chrono::milliseconds ns);
17u64 usToClockCycles(std::chrono::microseconds ns);
16u64 nsToClockCycles(std::chrono::nanoseconds ns); 18u64 nsToClockCycles(std::chrono::nanoseconds ns);
17 19
18inline std::chrono::milliseconds CyclesToMs(s64 cycles) { 20inline std::chrono::milliseconds CyclesToMs(s64 cycles) {
diff --git a/src/core/host_timing.cpp b/src/core/host_timing.cpp
index c734a118e..be80d9f8e 100644
--- a/src/core/host_timing.cpp
+++ b/src/core/host_timing.cpp
@@ -76,11 +76,11 @@ void CoreTiming::SyncPause(bool is_paused) {
76 ; 76 ;
77} 77}
78 78
79bool CoreTiming::IsRunning() { 79bool CoreTiming::IsRunning() const {
80 return !paused_set; 80 return !paused_set;
81} 81}
82 82
83bool CoreTiming::HasPendingEvents() { 83bool CoreTiming::HasPendingEvents() const {
84 return !(wait_set && event_queue.empty()); 84 return !(wait_set && event_queue.empty());
85} 85}
86 86
diff --git a/src/core/host_timing.h b/src/core/host_timing.h
index 15a150904..679fcf491 100644
--- a/src/core/host_timing.h
+++ b/src/core/host_timing.h
@@ -72,15 +72,15 @@ public:
72 void SyncPause(bool is_paused); 72 void SyncPause(bool is_paused);
73 73
74 /// Checks if core timing is running. 74 /// Checks if core timing is running.
75 bool IsRunning(); 75 bool IsRunning() const;
76 76
77 /// Checks if the timer thread has started. 77 /// Checks if the timer thread has started.
78 bool HasStarted() { 78 bool HasStarted() const {
79 return has_started; 79 return has_started;
80 } 80 }
81 81
82 /// Checks if there are any pending time events. 82 /// Checks if there are any pending time events.
83 bool HasPendingEvents(); 83 bool HasPendingEvents() const;
84 84
85 /// Schedules an event in core timing 85 /// Schedules an event in core timing
86 void ScheduleEvent(s64 ns_into_future, const std::shared_ptr<EventType>& event_type, 86 void ScheduleEvent(s64 ns_into_future, const std::shared_ptr<EventType>& event_type,
diff --git a/src/tests/common/fibers.cpp b/src/tests/common/fibers.cpp
index d63194dd4..0d3d5153d 100644
--- a/src/tests/common/fibers.cpp
+++ b/src/tests/common/fibers.cpp
@@ -34,7 +34,7 @@ public:
34}; 34};
35 35
36static void WorkControl1(void* control) { 36static void WorkControl1(void* control) {
37 TestControl1* test_control = static_cast<TestControl1*>(control); 37 auto* test_control = static_cast<TestControl1*>(control);
38 test_control->DoWork(); 38 test_control->DoWork();
39} 39}
40 40
@@ -70,8 +70,8 @@ static void ThreadStart1(u32 id, TestControl1& test_control) {
70TEST_CASE("Fibers::Setup", "[common]") { 70TEST_CASE("Fibers::Setup", "[common]") {
71 constexpr u32 num_threads = 7; 71 constexpr u32 num_threads = 7;
72 TestControl1 test_control{}; 72 TestControl1 test_control{};
73 test_control.thread_fibers.resize(num_threads, nullptr); 73 test_control.thread_fibers.resize(num_threads);
74 test_control.work_fibers.resize(num_threads, nullptr); 74 test_control.work_fibers.resize(num_threads);
75 test_control.items.resize(num_threads, 0); 75 test_control.items.resize(num_threads, 0);
76 test_control.results.resize(num_threads, 0); 76 test_control.results.resize(num_threads, 0);
77 std::vector<std::thread> threads; 77 std::vector<std::thread> threads;
@@ -153,17 +153,17 @@ public:
153}; 153};
154 154
155static void WorkControl2_1(void* control) { 155static void WorkControl2_1(void* control) {
156 TestControl2* test_control = static_cast<TestControl2*>(control); 156 auto* test_control = static_cast<TestControl2*>(control);
157 test_control->DoWork1(); 157 test_control->DoWork1();
158} 158}
159 159
160static void WorkControl2_2(void* control) { 160static void WorkControl2_2(void* control) {
161 TestControl2* test_control = static_cast<TestControl2*>(control); 161 auto* test_control = static_cast<TestControl2*>(control);
162 test_control->DoWork2(); 162 test_control->DoWork2();
163} 163}
164 164
165static void WorkControl2_3(void* control) { 165static void WorkControl2_3(void* control) {
166 TestControl2* test_control = static_cast<TestControl2*>(control); 166 auto* test_control = static_cast<TestControl2*>(control);
167 test_control->DoWork3(); 167 test_control->DoWork3();
168} 168}
169 169
@@ -198,7 +198,7 @@ static void ThreadStart2_2(u32 id, TestControl2& test_control) {
198 */ 198 */
199TEST_CASE("Fibers::InterExchange", "[common]") { 199TEST_CASE("Fibers::InterExchange", "[common]") {
200 TestControl2 test_control{}; 200 TestControl2 test_control{};
201 test_control.thread_fibers.resize(2, nullptr); 201 test_control.thread_fibers.resize(2);
202 test_control.fiber1 = 202 test_control.fiber1 =
203 std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_1}, &test_control); 203 std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_1}, &test_control);
204 test_control.fiber2 = 204 test_control.fiber2 =
@@ -261,12 +261,12 @@ public:
261}; 261};
262 262
263static void WorkControl3_1(void* control) { 263static void WorkControl3_1(void* control) {
264 TestControl3* test_control = static_cast<TestControl3*>(control); 264 auto* test_control = static_cast<TestControl3*>(control);
265 test_control->DoWork1(); 265 test_control->DoWork1();
266} 266}
267 267
268static void WorkControl3_2(void* control) { 268static void WorkControl3_2(void* control) {
269 TestControl3* test_control = static_cast<TestControl3*>(control); 269 auto* test_control = static_cast<TestControl3*>(control);
270 test_control->DoWork2(); 270 test_control->DoWork2();
271} 271}
272 272
@@ -295,7 +295,7 @@ static void ThreadStart3(u32 id, TestControl3& test_control) {
295 */ 295 */
296TEST_CASE("Fibers::StartRace", "[common]") { 296TEST_CASE("Fibers::StartRace", "[common]") {
297 TestControl3 test_control{}; 297 TestControl3 test_control{};
298 test_control.thread_fibers.resize(2, nullptr); 298 test_control.thread_fibers.resize(2);
299 test_control.fiber1 = 299 test_control.fiber1 =
300 std::make_shared<Fiber>(std::function<void(void*)>{WorkControl3_1}, &test_control); 300 std::make_shared<Fiber>(std::function<void(void*)>{WorkControl3_1}, &test_control);
301 test_control.fiber2 = 301 test_control.fiber2 =
diff --git a/src/tests/core/host_timing.cpp b/src/tests/core/host_timing.cpp
index 3d0532d02..ed060be55 100644
--- a/src/tests/core/host_timing.cpp
+++ b/src/tests/core/host_timing.cpp
@@ -50,13 +50,13 @@ struct ScopeInit final {
50TEST_CASE("HostTiming[BasicOrder]", "[core]") { 50TEST_CASE("HostTiming[BasicOrder]", "[core]") {
51 ScopeInit guard; 51 ScopeInit guard;
52 auto& core_timing = guard.core_timing; 52 auto& core_timing = guard.core_timing;
53 std::vector<std::shared_ptr<Core::HostTiming::EventType>> events; 53 std::vector<std::shared_ptr<Core::HostTiming::EventType>> events{
54 events.resize(5); 54 Core::HostTiming::CreateEvent("callbackA", HostCallbackTemplate<0>),
55 events[0] = Core::HostTiming::CreateEvent("callbackA", HostCallbackTemplate<0>); 55 Core::HostTiming::CreateEvent("callbackB", HostCallbackTemplate<1>),
56 events[1] = Core::HostTiming::CreateEvent("callbackB", HostCallbackTemplate<1>); 56 Core::HostTiming::CreateEvent("callbackC", HostCallbackTemplate<2>),
57 events[2] = Core::HostTiming::CreateEvent("callbackC", HostCallbackTemplate<2>); 57 Core::HostTiming::CreateEvent("callbackD", HostCallbackTemplate<3>),
58 events[3] = Core::HostTiming::CreateEvent("callbackD", HostCallbackTemplate<3>); 58 Core::HostTiming::CreateEvent("callbackE", HostCallbackTemplate<4>),
59 events[4] = Core::HostTiming::CreateEvent("callbackE", HostCallbackTemplate<4>); 59 };
60 60
61 expected_callback = 0; 61 expected_callback = 0;
62 62
@@ -100,13 +100,13 @@ u64 TestTimerSpeed(Core::HostTiming::CoreTiming& core_timing) {
100TEST_CASE("HostTiming[BasicOrderNoPausing]", "[core]") { 100TEST_CASE("HostTiming[BasicOrderNoPausing]", "[core]") {
101 ScopeInit guard; 101 ScopeInit guard;
102 auto& core_timing = guard.core_timing; 102 auto& core_timing = guard.core_timing;
103 std::vector<std::shared_ptr<Core::HostTiming::EventType>> events; 103 std::vector<std::shared_ptr<Core::HostTiming::EventType>> events{
104 events.resize(5); 104 Core::HostTiming::CreateEvent("callbackA", HostCallbackTemplate<0>),
105 events[0] = Core::HostTiming::CreateEvent("callbackA", HostCallbackTemplate<0>); 105 Core::HostTiming::CreateEvent("callbackB", HostCallbackTemplate<1>),
106 events[1] = Core::HostTiming::CreateEvent("callbackB", HostCallbackTemplate<1>); 106 Core::HostTiming::CreateEvent("callbackC", HostCallbackTemplate<2>),
107 events[2] = Core::HostTiming::CreateEvent("callbackC", HostCallbackTemplate<2>); 107 Core::HostTiming::CreateEvent("callbackD", HostCallbackTemplate<3>),
108 events[3] = Core::HostTiming::CreateEvent("callbackD", HostCallbackTemplate<3>); 108 Core::HostTiming::CreateEvent("callbackE", HostCallbackTemplate<4>),
109 events[4] = Core::HostTiming::CreateEvent("callbackE", HostCallbackTemplate<4>); 109 };
110 110
111 core_timing.SyncPause(true); 111 core_timing.SyncPause(true);
112 core_timing.SyncPause(false); 112 core_timing.SyncPause(false);