aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorlizzie <lizzie@eden-emu.dev>2026-09-16 15:35:13 +0200
committercrueter <crueter@eden-emu.dev>2026-09-16 15:35:13 +0200
commitac35358b3ffed74aaac56b0e99b09e81bb60d2e1 (patch)
tree1bb14ab1d393d42b592ebdef86614aa68b01aefa /src/common
parent7bf95be2c29328a4cfeb8b2384ce34c6fb6d890c (diff)
[common] Replace `Common::SpinLock` with `std::mutex` (#4436)
`std::mutex` can be better than the spin-lock specially since we don't waste CPU cycles for no reason. Test less stuttering/heat consumption. Signed-off-by: lizzie <lizzie@eden-emu.dev> - [x] I have read and followed the [Contribution Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/CONTRIBUTING.md#code-contributions). - [x] I have read and followed the [AI Policy](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/AI.md) - [x] I have read and followed the [Coding Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/Coding.md) to the best of my ability. ------------------- Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4436 Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/spin_lock.h50
2 files changed, 0 insertions, 51 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 61e0e64aa8..94da1724df 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -110,7 +110,6 @@ add_library(
socket_types.h
sparse_large_vector.cpp
sparse_large_vector.h
- spin_lock.h
stb.cpp
stb.h
steady_clock.cpp
diff --git a/src/common/spin_lock.h b/src/common/spin_lock.h
deleted file mode 100644
index 93d507ae80..0000000000
--- a/src/common/spin_lock.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-#pragma once
-
-#ifdef _MSC_VER
-#include <intrin.h>
-#elif defined(ARCHITECTURE_x86_64)
-#include <xmmintrin.h>
-#endif
-#include <atomic>
-
-namespace Common {
-
-/// @brief A lock similar to mutex that forces a thread to spin wait instead calling the
-/// supervisor. Should be used on short sequences of code.
-struct SpinLock {
- SpinLock() noexcept = default;
- SpinLock(const SpinLock&) noexcept = delete;
- SpinLock& operator=(const SpinLock&) noexcept = delete;
- SpinLock(SpinLock&&) noexcept = delete;
- SpinLock& operator=(SpinLock&&) noexcept = delete;
-
- inline void lock() noexcept {
- while (lck.test_and_set(std::memory_order_acquire)) {
-#if defined(ARCHITECTURE_x86_64)
- _mm_pause();
-#elif defined(ARCHITECTURE_arm64) && defined(_MSC_VER)
- __yield();
-#elif defined(ARCHITECTURE_arm64)
- asm("yield");
-#endif
- }
- }
-
- inline void unlock() noexcept {
- lck.clear(std::memory_order_release);
- }
-
- [[nodiscard]] inline bool try_lock() noexcept {
- return !lck.test_and_set(std::memory_order_acquire);
- }
-
- std::atomic_flag lck = ATOMIC_FLAG_INIT;
-};
-
-} // namespace Common