summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2020-02-10 13:33:13 -0400
committerGravatar Fernando Sahmkow2020-06-18 16:29:19 -0400
commit1bd706344e2381e11245b2f0bdc291429e46c634 (patch)
tree4abae5a2088df1eb023967d83c0b808eceb30cea /src
parentCommon: Correct fcontext fibers. (diff)
downloadyuzu-1bd706344e2381e11245b2f0bdc291429e46c634.tar.gz
yuzu-1bd706344e2381e11245b2f0bdc291429e46c634.tar.xz
yuzu-1bd706344e2381e11245b2f0bdc291429e46c634.zip
Common/Tests: Clang Format.
Diffstat (limited to 'src')
-rw-r--r--src/common/fiber.cpp21
-rw-r--r--src/common/fiber.h2
-rw-r--r--src/common/wall_clock.cpp12
-rw-r--r--src/common/wall_clock.h4
-rw-r--r--src/core/host_timing.cpp8
-rw-r--r--src/core/host_timing.h2
-rw-r--r--src/tests/common/fibers.cpp23
7 files changed, 41 insertions, 31 deletions
diff --git a/src/common/fiber.cpp b/src/common/fiber.cpp
index e91d86dbe..a46be73c1 100644
--- a/src/common/fiber.cpp
+++ b/src/common/fiber.cpp
@@ -12,7 +12,6 @@
12 12
13namespace Common { 13namespace Common {
14 14
15
16#ifdef _MSC_VER 15#ifdef _MSC_VER
17 16
18struct Fiber::FiberImpl { 17struct Fiber::FiberImpl {
@@ -27,14 +26,14 @@ void Fiber::start() {
27 UNREACHABLE(); 26 UNREACHABLE();
28} 27}
29 28
30void __stdcall Fiber::FiberStartFunc(void* fiber_parameter) 29void __stdcall Fiber::FiberStartFunc(void* fiber_parameter) {
31{ 30 auto fiber = static_cast<Fiber*>(fiber_parameter);
32 auto fiber = static_cast<Fiber *>(fiber_parameter); 31 fiber->start();
33 fiber->start();
34} 32}
35 33
36Fiber::Fiber(std::function<void(void*)>&& entry_point_func, void* start_parameter) 34Fiber::Fiber(std::function<void(void*)>&& entry_point_func, void* start_parameter)
37 : guard{}, entry_point{std::move(entry_point_func)}, start_parameter{start_parameter}, previous_fiber{} { 35 : guard{}, entry_point{std::move(entry_point_func)}, start_parameter{start_parameter},
36 previous_fiber{} {
38 impl = std::make_unique<FiberImpl>(); 37 impl = std::make_unique<FiberImpl>();
39 impl->handle = CreateFiber(0, &FiberStartFunc, this); 38 impl->handle = CreateFiber(0, &FiberStartFunc, this);
40} 39}
@@ -99,14 +98,14 @@ void Fiber::start(boost::context::detail::transfer_t& transfer) {
99 UNREACHABLE(); 98 UNREACHABLE();
100} 99}
101 100
102void Fiber::FiberStartFunc(boost::context::detail::transfer_t transfer) 101void Fiber::FiberStartFunc(boost::context::detail::transfer_t transfer) {
103{ 102 auto fiber = static_cast<Fiber*>(transfer.data);
104 auto fiber = static_cast<Fiber *>(transfer.data); 103 fiber->start(transfer);
105 fiber->start(transfer);
106} 104}
107 105
108Fiber::Fiber(std::function<void(void*)>&& entry_point_func, void* start_parameter) 106Fiber::Fiber(std::function<void(void*)>&& entry_point_func, void* start_parameter)
109 : guard{}, entry_point{std::move(entry_point_func)}, start_parameter{start_parameter}, previous_fiber{} { 107 : guard{}, entry_point{std::move(entry_point_func)}, start_parameter{start_parameter},
108 previous_fiber{} {
110 impl = std::make_unique<FiberImpl>(); 109 impl = std::make_unique<FiberImpl>();
111 impl->context = boost::context::detail::make_fcontext(impl->stack.data(), impl->stack.size(), 110 impl->context = boost::context::detail::make_fcontext(impl->stack.data(), impl->stack.size(),
112 FiberStartFunc); 111 FiberStartFunc);
diff --git a/src/common/fiber.h b/src/common/fiber.h
index 89a01fdd8..b530bf4d2 100644
--- a/src/common/fiber.h
+++ b/src/common/fiber.h
@@ -12,7 +12,7 @@
12 12
13#ifndef _MSC_VER 13#ifndef _MSC_VER
14namespace boost::context::detail { 14namespace boost::context::detail {
15 struct transfer_t; 15struct transfer_t;
16} 16}
17#endif 17#endif
18 18
diff --git a/src/common/wall_clock.cpp b/src/common/wall_clock.cpp
index 8f5e17fa4..e6161c72c 100644
--- a/src/common/wall_clock.cpp
+++ b/src/common/wall_clock.cpp
@@ -58,7 +58,8 @@ private:
58 58
59#ifdef ARCHITECTURE_x86_64 59#ifdef ARCHITECTURE_x86_64
60 60
61std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency, u32 emulated_clock_frequency) { 61std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency,
62 u32 emulated_clock_frequency) {
62 const auto& caps = GetCPUCaps(); 63 const auto& caps = GetCPUCaps();
63 u64 rtsc_frequency = 0; 64 u64 rtsc_frequency = 0;
64 if (caps.invariant_tsc) { 65 if (caps.invariant_tsc) {
@@ -70,15 +71,18 @@ std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency, u
70 } 71 }
71 } 72 }
72 if (rtsc_frequency == 0) { 73 if (rtsc_frequency == 0) {
73 return std::make_unique<StandardWallClock>(emulated_cpu_frequency, emulated_clock_frequency); 74 return std::make_unique<StandardWallClock>(emulated_cpu_frequency,
75 emulated_clock_frequency);
74 } else { 76 } else {
75 return std::make_unique<X64::NativeClock>(emulated_cpu_frequency, emulated_clock_frequency, rtsc_frequency); 77 return std::make_unique<X64::NativeClock>(emulated_cpu_frequency, emulated_clock_frequency,
78 rtsc_frequency);
76 } 79 }
77} 80}
78 81
79#else 82#else
80 83
81std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency, u32 emulated_clock_frequency) { 84std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency,
85 u32 emulated_clock_frequency) {
82 return std::make_unique<StandardWallClock>(emulated_cpu_frequency, emulated_clock_frequency); 86 return std::make_unique<StandardWallClock>(emulated_cpu_frequency, emulated_clock_frequency);
83} 87}
84 88
diff --git a/src/common/wall_clock.h b/src/common/wall_clock.h
index fc34429bb..ed284cf50 100644
--- a/src/common/wall_clock.h
+++ b/src/common/wall_clock.h
@@ -13,7 +13,6 @@ namespace Common {
13 13
14class WallClock { 14class WallClock {
15public: 15public:
16
17 /// Returns current wall time in nanoseconds 16 /// Returns current wall time in nanoseconds
18 virtual std::chrono::nanoseconds GetTimeNS() = 0; 17 virtual std::chrono::nanoseconds GetTimeNS() = 0;
19 18
@@ -46,6 +45,7 @@ private:
46 bool is_native; 45 bool is_native;
47}; 46};
48 47
49std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency, u32 emulated_clock_frequency); 48std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency,
49 u32 emulated_clock_frequency);
50 50
51} // namespace Common 51} // namespace Common
diff --git a/src/core/host_timing.cpp b/src/core/host_timing.cpp
index 4ccf7c6c1..c734a118e 100644
--- a/src/core/host_timing.cpp
+++ b/src/core/host_timing.cpp
@@ -72,7 +72,8 @@ void CoreTiming::SyncPause(bool is_paused) {
72 } 72 }
73 Pause(is_paused); 73 Pause(is_paused);
74 event.Set(); 74 event.Set();
75 while (paused_set != is_paused); 75 while (paused_set != is_paused)
76 ;
76} 77}
77 78
78bool CoreTiming::IsRunning() { 79bool CoreTiming::IsRunning() {
@@ -158,7 +159,8 @@ void CoreTiming::Advance() {
158 } 159 }
159 160
160 if (!event_queue.empty()) { 161 if (!event_queue.empty()) {
161 std::chrono::nanoseconds next_time = std::chrono::nanoseconds(event_queue.front().time - global_timer); 162 std::chrono::nanoseconds next_time =
163 std::chrono::nanoseconds(event_queue.front().time - global_timer);
162 basic_lock.unlock(); 164 basic_lock.unlock();
163 event.WaitFor(next_time); 165 event.WaitFor(next_time);
164 } else { 166 } else {
@@ -181,4 +183,4 @@ std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const {
181 return clock->GetTimeUS(); 183 return clock->GetTimeUS();
182} 184}
183 185
184} // namespace Core::Timing 186} // namespace Core::HostTiming
diff --git a/src/core/host_timing.h b/src/core/host_timing.h
index f04a150ee..15a150904 100644
--- a/src/core/host_timing.h
+++ b/src/core/host_timing.h
@@ -145,4 +145,4 @@ private:
145/// 145///
146std::shared_ptr<EventType> CreateEvent(std::string name, TimedCallback&& callback); 146std::shared_ptr<EventType> CreateEvent(std::string name, TimedCallback&& callback);
147 147
148} // namespace Core::Timing 148} // namespace Core::HostTiming
diff --git a/src/tests/common/fibers.cpp b/src/tests/common/fibers.cpp
index 358393a19..d63194dd4 100644
--- a/src/tests/common/fibers.cpp
+++ b/src/tests/common/fibers.cpp
@@ -92,7 +92,8 @@ public:
92 92
93 void DoWork1() { 93 void DoWork1() {
94 trap2 = false; 94 trap2 = false;
95 while (trap.load()); 95 while (trap.load())
96 ;
96 for (u32 i = 0; i < 12000; i++) { 97 for (u32 i = 0; i < 12000; i++) {
97 value1 += i; 98 value1 += i;
98 } 99 }
@@ -105,7 +106,8 @@ public:
105 } 106 }
106 107
107 void DoWork2() { 108 void DoWork2() {
108 while (trap2.load()); 109 while (trap2.load())
110 ;
109 value2 = 2000; 111 value2 = 2000;
110 trap = false; 112 trap = false;
111 Fiber::YieldTo(fiber2, fiber1); 113 Fiber::YieldTo(fiber2, fiber1);
@@ -197,9 +199,12 @@ static void ThreadStart2_2(u32 id, TestControl2& test_control) {
197TEST_CASE("Fibers::InterExchange", "[common]") { 199TEST_CASE("Fibers::InterExchange", "[common]") {
198 TestControl2 test_control{}; 200 TestControl2 test_control{};
199 test_control.thread_fibers.resize(2, nullptr); 201 test_control.thread_fibers.resize(2, nullptr);
200 test_control.fiber1 = std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_1}, &test_control); 202 test_control.fiber1 =
201 test_control.fiber2 = std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_2}, &test_control); 203 std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_1}, &test_control);
202 test_control.fiber3 = std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_3}, &test_control); 204 test_control.fiber2 =
205 std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_2}, &test_control);
206 test_control.fiber3 =
207 std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_3}, &test_control);
203 std::thread thread1(ThreadStart2_1, 0, std::ref(test_control)); 208 std::thread thread1(ThreadStart2_1, 0, std::ref(test_control));
204 std::thread thread2(ThreadStart2_2, 1, std::ref(test_control)); 209 std::thread thread2(ThreadStart2_2, 1, std::ref(test_control));
205 thread1.join(); 210 thread1.join();
@@ -291,8 +296,10 @@ static void ThreadStart3(u32 id, TestControl3& test_control) {
291TEST_CASE("Fibers::StartRace", "[common]") { 296TEST_CASE("Fibers::StartRace", "[common]") {
292 TestControl3 test_control{}; 297 TestControl3 test_control{};
293 test_control.thread_fibers.resize(2, nullptr); 298 test_control.thread_fibers.resize(2, nullptr);
294 test_control.fiber1 = std::make_shared<Fiber>(std::function<void(void*)>{WorkControl3_1}, &test_control); 299 test_control.fiber1 =
295 test_control.fiber2 = std::make_shared<Fiber>(std::function<void(void*)>{WorkControl3_2}, &test_control); 300 std::make_shared<Fiber>(std::function<void(void*)>{WorkControl3_1}, &test_control);
301 test_control.fiber2 =
302 std::make_shared<Fiber>(std::function<void(void*)>{WorkControl3_2}, &test_control);
296 std::thread thread1(ThreadStart3, 0, std::ref(test_control)); 303 std::thread thread1(ThreadStart3, 0, std::ref(test_control));
297 std::thread thread2(ThreadStart3, 1, std::ref(test_control)); 304 std::thread thread2(ThreadStart3, 1, std::ref(test_control));
298 thread1.join(); 305 thread1.join();
@@ -302,6 +309,4 @@ TEST_CASE("Fibers::StartRace", "[common]") {
302 REQUIRE(test_control.value3 == 1); 309 REQUIRE(test_control.value3 == 1);
303} 310}
304 311
305
306
307} // namespace Common 312} // namespace Common