summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2020-06-28 00:20:06 +0200
committerFernando Sahmkow <fsahmkow27@gmail.com>2020-06-28 00:20:06 +0200
commit2f8947583f2f0af4058600243d6c1d244e3c4890 (patch)
treea0e7a10c6131efb23d6fdb3ee7fc0de4bd4163af /src/common
parentNvFlinger: Clang Format. (diff)
downloadyuzu-2f8947583f2f0af4058600243d6c1d244e3c4890.tar
yuzu-2f8947583f2f0af4058600243d6c1d244e3c4890.tar.gz
yuzu-2f8947583f2f0af4058600243d6c1d244e3c4890.tar.bz2
yuzu-2f8947583f2f0af4058600243d6c1d244e3c4890.tar.lz
yuzu-2f8947583f2f0af4058600243d6c1d244e3c4890.tar.xz
yuzu-2f8947583f2f0af4058600243d6c1d244e3c4890.tar.zst
yuzu-2f8947583f2f0af4058600243d6c1d244e3c4890.zip
Diffstat (limited to 'src/common')
-rw-r--r--src/common/fiber.cpp10
-rw-r--r--src/common/spin_lock.cpp6
-rw-r--r--src/common/spin_lock.h5
-rw-r--r--src/common/x64/native_clock.cpp4
4 files changed, 13 insertions, 12 deletions
diff --git a/src/common/fiber.cpp b/src/common/fiber.cpp
index f97ad433b..1c1d09ccb 100644
--- a/src/common/fiber.cpp
+++ b/src/common/fiber.cpp
@@ -54,9 +54,7 @@ Fiber::Fiber(std::function<void(void*)>&& entry_point_func, void* start_paramete
impl->handle = CreateFiber(default_stack_size, &FiberStartFunc, this);
}
-Fiber::Fiber() {
- impl = std::make_unique<FiberImpl>();
-}
+Fiber::Fiber() : impl{std::make_unique<FiberImpl>()} {}
Fiber::~Fiber() {
if (released) {
@@ -116,8 +114,8 @@ std::shared_ptr<Fiber> Fiber::ThreadToFiber() {
struct Fiber::FiberImpl {
alignas(64) std::array<u8, default_stack_size> stack;
- u8* stack_limit;
alignas(64) std::array<u8, default_stack_size> rewind_stack;
+ u8* stack_limit;
u8* rewind_stack_limit;
boost::context::detail::fcontext_t context;
boost::context::detail::fcontext_t rewind_context;
@@ -168,9 +166,7 @@ void Fiber::SetRewindPoint(std::function<void(void*)>&& rewind_func, void* start
rewind_parameter = start_parameter;
}
-Fiber::Fiber() {
- impl = std::make_unique<FiberImpl>();
-}
+Fiber::Fiber() : impl{std::make_unique<FiberImpl>()} {}
Fiber::~Fiber() {
if (released) {
diff --git a/src/common/spin_lock.cpp b/src/common/spin_lock.cpp
index c7b46aac6..c1524220f 100644
--- a/src/common/spin_lock.cpp
+++ b/src/common/spin_lock.cpp
@@ -20,7 +20,7 @@
namespace {
-void thread_pause() {
+void ThreadPause() {
#if __x86_64__
_mm_pause();
#elif __aarch64__ && _MSC_VER
@@ -30,13 +30,13 @@ void thread_pause() {
#endif
}
-} // namespace
+} // Anonymous namespace
namespace Common {
void SpinLock::lock() {
while (lck.test_and_set(std::memory_order_acquire)) {
- thread_pause();
+ ThreadPause();
}
}
diff --git a/src/common/spin_lock.h b/src/common/spin_lock.h
index 70282a961..1df5528c4 100644
--- a/src/common/spin_lock.h
+++ b/src/common/spin_lock.h
@@ -8,6 +8,11 @@
namespace Common {
+/**
+ * SpinLock class
+ * a lock similar to mutex that forces a thread to spin wait instead calling the
+ * supervisor. Should be used on short sequences of code.
+ */
class SpinLock {
public:
void lock();
diff --git a/src/common/x64/native_clock.cpp b/src/common/x64/native_clock.cpp
index f1bc60fd2..424b39b1f 100644
--- a/src/common/x64/native_clock.cpp
+++ b/src/common/x64/native_clock.cpp
@@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <chrono>
+#include <mutex>
#include <thread>
#ifdef _MSC_VER
@@ -52,7 +53,7 @@ NativeClock::NativeClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequenc
}
u64 NativeClock::GetRTSC() {
- rtsc_serialize.lock();
+ std::scoped_lock scope{rtsc_serialize};
_mm_mfence();
const u64 current_measure = __rdtsc();
u64 diff = current_measure - last_measure;
@@ -61,7 +62,6 @@ u64 NativeClock::GetRTSC() {
last_measure = current_measure;
}
accumulated_ticks += diff;
- rtsc_serialize.unlock();
/// The clock cannot be more precise than the guest timer, remove the lower bits
return accumulated_ticks & inaccuracy_mask;
}