diff options
Diffstat (limited to 'src/common/spin_lock.h')
| -rw-r--r-- | src/common/spin_lock.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/common/spin_lock.h b/src/common/spin_lock.h new file mode 100644 index 000000000..1df5528c4 --- /dev/null +++ b/src/common/spin_lock.h | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <atomic> | ||
| 8 | |||
| 9 | namespace Common { | ||
| 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 | */ | ||
| 16 | class SpinLock { | ||
| 17 | public: | ||
| 18 | void lock(); | ||
| 19 | void unlock(); | ||
| 20 | bool try_lock(); | ||
| 21 | |||
| 22 | private: | ||
| 23 | std::atomic_flag lck = ATOMIC_FLAG_INIT; | ||
| 24 | }; | ||
| 25 | |||
| 26 | } // namespace Common | ||