diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/fiber.cpp | 10 | ||||
| -rw-r--r-- | src/common/spin_lock.cpp | 6 | ||||
| -rw-r--r-- | src/common/spin_lock.h | 5 | ||||
| -rw-r--r-- | src/common/x64/native_clock.cpp | 4 |
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 | |||
| 54 | impl->handle = CreateFiber(default_stack_size, &FiberStartFunc, this); | 54 | impl->handle = CreateFiber(default_stack_size, &FiberStartFunc, this); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | Fiber::Fiber() { | 57 | Fiber::Fiber() : impl{std::make_unique<FiberImpl>()} {} |
| 58 | impl = std::make_unique<FiberImpl>(); | ||
| 59 | } | ||
| 60 | 58 | ||
| 61 | Fiber::~Fiber() { | 59 | Fiber::~Fiber() { |
| 62 | if (released) { | 60 | if (released) { |
| @@ -116,8 +114,8 @@ std::shared_ptr<Fiber> Fiber::ThreadToFiber() { | |||
| 116 | 114 | ||
| 117 | struct Fiber::FiberImpl { | 115 | struct Fiber::FiberImpl { |
| 118 | alignas(64) std::array<u8, default_stack_size> stack; | 116 | alignas(64) std::array<u8, default_stack_size> stack; |
| 119 | u8* stack_limit; | ||
| 120 | alignas(64) std::array<u8, default_stack_size> rewind_stack; | 117 | alignas(64) std::array<u8, default_stack_size> rewind_stack; |
| 118 | u8* stack_limit; | ||
| 121 | u8* rewind_stack_limit; | 119 | u8* rewind_stack_limit; |
| 122 | boost::context::detail::fcontext_t context; | 120 | boost::context::detail::fcontext_t context; |
| 123 | boost::context::detail::fcontext_t rewind_context; | 121 | boost::context::detail::fcontext_t rewind_context; |
| @@ -168,9 +166,7 @@ void Fiber::SetRewindPoint(std::function<void(void*)>&& rewind_func, void* start | |||
| 168 | rewind_parameter = start_parameter; | 166 | rewind_parameter = start_parameter; |
| 169 | } | 167 | } |
| 170 | 168 | ||
| 171 | Fiber::Fiber() { | 169 | Fiber::Fiber() : impl{std::make_unique<FiberImpl>()} {} |
| 172 | impl = std::make_unique<FiberImpl>(); | ||
| 173 | } | ||
| 174 | 170 | ||
| 175 | Fiber::~Fiber() { | 171 | Fiber::~Fiber() { |
| 176 | if (released) { | 172 | 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 @@ | |||
| 20 | 20 | ||
| 21 | namespace { | 21 | namespace { |
| 22 | 22 | ||
| 23 | void thread_pause() { | 23 | void ThreadPause() { |
| 24 | #if __x86_64__ | 24 | #if __x86_64__ |
| 25 | _mm_pause(); | 25 | _mm_pause(); |
| 26 | #elif __aarch64__ && _MSC_VER | 26 | #elif __aarch64__ && _MSC_VER |
| @@ -30,13 +30,13 @@ void thread_pause() { | |||
| 30 | #endif | 30 | #endif |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | } // namespace | 33 | } // Anonymous namespace |
| 34 | 34 | ||
| 35 | namespace Common { | 35 | namespace Common { |
| 36 | 36 | ||
| 37 | void SpinLock::lock() { | 37 | void 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 | ThreadPause(); |
| 40 | } | 40 | } |
| 41 | } | 41 | } |
| 42 | 42 | ||
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 @@ | |||
| 8 | 8 | ||
| 9 | namespace Common { | 9 | namespace Common { |
| 10 | 10 | ||
| 11 | /** | ||
| 12 | * SpinLock class | ||
| 13 | * a lock similar to mutex that forces a thread to spin wait instead calling the | ||
| 14 | * supervisor. Should be used on short sequences of code. | ||
| 15 | */ | ||
| 11 | class SpinLock { | 16 | class SpinLock { |
| 12 | public: | 17 | public: |
| 13 | void lock(); | 18 | 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 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <chrono> | 5 | #include <chrono> |
| 6 | #include <mutex> | ||
| 6 | #include <thread> | 7 | #include <thread> |
| 7 | 8 | ||
| 8 | #ifdef _MSC_VER | 9 | #ifdef _MSC_VER |
| @@ -52,7 +53,7 @@ NativeClock::NativeClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequenc | |||
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | u64 NativeClock::GetRTSC() { | 55 | u64 NativeClock::GetRTSC() { |
| 55 | rtsc_serialize.lock(); | 56 | std::scoped_lock scope{rtsc_serialize}; |
| 56 | _mm_mfence(); | 57 | _mm_mfence(); |
| 57 | const u64 current_measure = __rdtsc(); | 58 | const u64 current_measure = __rdtsc(); |
| 58 | u64 diff = current_measure - last_measure; | 59 | u64 diff = current_measure - last_measure; |
| @@ -61,7 +62,6 @@ u64 NativeClock::GetRTSC() { | |||
| 61 | last_measure = current_measure; | 62 | last_measure = current_measure; |
| 62 | } | 63 | } |
| 63 | accumulated_ticks += diff; | 64 | accumulated_ticks += diff; |
| 64 | rtsc_serialize.unlock(); | ||
| 65 | /// The clock cannot be more precise than the guest timer, remove the lower bits | 65 | /// The clock cannot be more precise than the guest timer, remove the lower bits |
| 66 | return accumulated_ticks & inaccuracy_mask; | 66 | return accumulated_ticks & inaccuracy_mask; |
| 67 | } | 67 | } |