forked from ShuriZma/suyu
1
0
Fork 0

Common/Tests: Clang Format.

This commit is contained in:
Fernando Sahmkow 2020-02-10 13:33:13 -04:00
parent 03e4f5dac4
commit 1bd706344e
7 changed files with 41 additions and 31 deletions

View File

@ -12,7 +12,6 @@
namespace Common { namespace Common {
#ifdef _MSC_VER #ifdef _MSC_VER
struct Fiber::FiberImpl { struct Fiber::FiberImpl {
@ -27,14 +26,14 @@ void Fiber::start() {
UNREACHABLE(); UNREACHABLE();
} }
void __stdcall Fiber::FiberStartFunc(void* fiber_parameter) void __stdcall Fiber::FiberStartFunc(void* fiber_parameter) {
{ auto fiber = static_cast<Fiber*>(fiber_parameter);
auto fiber = static_cast<Fiber *>(fiber_parameter); fiber->start();
fiber->start();
} }
Fiber::Fiber(std::function<void(void*)>&& entry_point_func, void* start_parameter) Fiber::Fiber(std::function<void(void*)>&& entry_point_func, void* start_parameter)
: guard{}, entry_point{std::move(entry_point_func)}, start_parameter{start_parameter}, previous_fiber{} { : guard{}, entry_point{std::move(entry_point_func)}, start_parameter{start_parameter},
previous_fiber{} {
impl = std::make_unique<FiberImpl>(); impl = std::make_unique<FiberImpl>();
impl->handle = CreateFiber(0, &FiberStartFunc, this); impl->handle = CreateFiber(0, &FiberStartFunc, this);
} }
@ -99,14 +98,14 @@ void Fiber::start(boost::context::detail::transfer_t& transfer) {
UNREACHABLE(); UNREACHABLE();
} }
void Fiber::FiberStartFunc(boost::context::detail::transfer_t transfer) void Fiber::FiberStartFunc(boost::context::detail::transfer_t transfer) {
{ auto fiber = static_cast<Fiber*>(transfer.data);
auto fiber = static_cast<Fiber *>(transfer.data); fiber->start(transfer);
fiber->start(transfer);
} }
Fiber::Fiber(std::function<void(void*)>&& entry_point_func, void* start_parameter) Fiber::Fiber(std::function<void(void*)>&& entry_point_func, void* start_parameter)
: guard{}, entry_point{std::move(entry_point_func)}, start_parameter{start_parameter}, previous_fiber{} { : guard{}, entry_point{std::move(entry_point_func)}, start_parameter{start_parameter},
previous_fiber{} {
impl = std::make_unique<FiberImpl>(); impl = std::make_unique<FiberImpl>();
impl->context = boost::context::detail::make_fcontext(impl->stack.data(), impl->stack.size(), impl->context = boost::context::detail::make_fcontext(impl->stack.data(), impl->stack.size(),
FiberStartFunc); FiberStartFunc);

View File

@ -12,7 +12,7 @@
#ifndef _MSC_VER #ifndef _MSC_VER
namespace boost::context::detail { namespace boost::context::detail {
struct transfer_t; struct transfer_t;
} }
#endif #endif

View File

@ -58,7 +58,8 @@ private:
#ifdef ARCHITECTURE_x86_64 #ifdef ARCHITECTURE_x86_64
std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency, u32 emulated_clock_frequency) { std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency,
u32 emulated_clock_frequency) {
const auto& caps = GetCPUCaps(); const auto& caps = GetCPUCaps();
u64 rtsc_frequency = 0; u64 rtsc_frequency = 0;
if (caps.invariant_tsc) { if (caps.invariant_tsc) {
@ -70,15 +71,18 @@ std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency, u
} }
} }
if (rtsc_frequency == 0) { if (rtsc_frequency == 0) {
return std::make_unique<StandardWallClock>(emulated_cpu_frequency, emulated_clock_frequency); return std::make_unique<StandardWallClock>(emulated_cpu_frequency,
emulated_clock_frequency);
} else { } else {
return std::make_unique<X64::NativeClock>(emulated_cpu_frequency, emulated_clock_frequency, rtsc_frequency); return std::make_unique<X64::NativeClock>(emulated_cpu_frequency, emulated_clock_frequency,
rtsc_frequency);
} }
} }
#else #else
std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency, u32 emulated_clock_frequency) { std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency,
u32 emulated_clock_frequency) {
return std::make_unique<StandardWallClock>(emulated_cpu_frequency, emulated_clock_frequency); return std::make_unique<StandardWallClock>(emulated_cpu_frequency, emulated_clock_frequency);
} }

View File

@ -13,7 +13,6 @@ namespace Common {
class WallClock { class WallClock {
public: public:
/// Returns current wall time in nanoseconds /// Returns current wall time in nanoseconds
virtual std::chrono::nanoseconds GetTimeNS() = 0; virtual std::chrono::nanoseconds GetTimeNS() = 0;
@ -46,6 +45,7 @@ private:
bool is_native; bool is_native;
}; };
std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency, u32 emulated_clock_frequency); std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency,
u32 emulated_clock_frequency);
} // namespace Common } // namespace Common

View File

@ -72,7 +72,8 @@ void CoreTiming::SyncPause(bool is_paused) {
} }
Pause(is_paused); Pause(is_paused);
event.Set(); event.Set();
while (paused_set != is_paused); while (paused_set != is_paused)
;
} }
bool CoreTiming::IsRunning() { bool CoreTiming::IsRunning() {
@ -158,7 +159,8 @@ void CoreTiming::Advance() {
} }
if (!event_queue.empty()) { if (!event_queue.empty()) {
std::chrono::nanoseconds next_time = std::chrono::nanoseconds(event_queue.front().time - global_timer); std::chrono::nanoseconds next_time =
std::chrono::nanoseconds(event_queue.front().time - global_timer);
basic_lock.unlock(); basic_lock.unlock();
event.WaitFor(next_time); event.WaitFor(next_time);
} else { } else {
@ -181,4 +183,4 @@ std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const {
return clock->GetTimeUS(); return clock->GetTimeUS();
} }
} // namespace Core::Timing } // namespace Core::HostTiming

View File

@ -145,4 +145,4 @@ private:
/// ///
std::shared_ptr<EventType> CreateEvent(std::string name, TimedCallback&& callback); std::shared_ptr<EventType> CreateEvent(std::string name, TimedCallback&& callback);
} // namespace Core::Timing } // namespace Core::HostTiming

View File

@ -92,7 +92,8 @@ public:
void DoWork1() { void DoWork1() {
trap2 = false; trap2 = false;
while (trap.load()); while (trap.load())
;
for (u32 i = 0; i < 12000; i++) { for (u32 i = 0; i < 12000; i++) {
value1 += i; value1 += i;
} }
@ -105,7 +106,8 @@ public:
} }
void DoWork2() { void DoWork2() {
while (trap2.load()); while (trap2.load())
;
value2 = 2000; value2 = 2000;
trap = false; trap = false;
Fiber::YieldTo(fiber2, fiber1); Fiber::YieldTo(fiber2, fiber1);
@ -197,9 +199,12 @@ static void ThreadStart2_2(u32 id, TestControl2& test_control) {
TEST_CASE("Fibers::InterExchange", "[common]") { TEST_CASE("Fibers::InterExchange", "[common]") {
TestControl2 test_control{}; TestControl2 test_control{};
test_control.thread_fibers.resize(2, nullptr); test_control.thread_fibers.resize(2, nullptr);
test_control.fiber1 = std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_1}, &test_control); test_control.fiber1 =
test_control.fiber2 = std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_2}, &test_control); std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_1}, &test_control);
test_control.fiber3 = std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_3}, &test_control); test_control.fiber2 =
std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_2}, &test_control);
test_control.fiber3 =
std::make_shared<Fiber>(std::function<void(void*)>{WorkControl2_3}, &test_control);
std::thread thread1(ThreadStart2_1, 0, std::ref(test_control)); std::thread thread1(ThreadStart2_1, 0, std::ref(test_control));
std::thread thread2(ThreadStart2_2, 1, std::ref(test_control)); std::thread thread2(ThreadStart2_2, 1, std::ref(test_control));
thread1.join(); thread1.join();
@ -291,8 +296,10 @@ static void ThreadStart3(u32 id, TestControl3& test_control) {
TEST_CASE("Fibers::StartRace", "[common]") { TEST_CASE("Fibers::StartRace", "[common]") {
TestControl3 test_control{}; TestControl3 test_control{};
test_control.thread_fibers.resize(2, nullptr); test_control.thread_fibers.resize(2, nullptr);
test_control.fiber1 = std::make_shared<Fiber>(std::function<void(void*)>{WorkControl3_1}, &test_control); test_control.fiber1 =
test_control.fiber2 = std::make_shared<Fiber>(std::function<void(void*)>{WorkControl3_2}, &test_control); std::make_shared<Fiber>(std::function<void(void*)>{WorkControl3_1}, &test_control);
test_control.fiber2 =
std::make_shared<Fiber>(std::function<void(void*)>{WorkControl3_2}, &test_control);
std::thread thread1(ThreadStart3, 0, std::ref(test_control)); std::thread thread1(ThreadStart3, 0, std::ref(test_control));
std::thread thread2(ThreadStart3, 1, std::ref(test_control)); std::thread thread2(ThreadStart3, 1, std::ref(test_control));
thread1.join(); thread1.join();
@ -302,6 +309,4 @@ TEST_CASE("Fibers::StartRace", "[common]") {
REQUIRE(test_control.value3 == 1); REQUIRE(test_control.value3 == 1);
} }
} // namespace Common } // namespace Common