A tool for deriving PKG packet encryption keys for ps4 written in c++
| 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include <atomic> |
| 7 | |
| 8 | namespace Common { |
| 9 | |
| 10 | /** |
| 11 | * SpinLock class |
| 12 | * a lock similar to mutex that forces a thread to spin wait instead calling the |
| 13 | * supervisor. Should be used on short sequences of code. |
| 14 | */ |
| 15 | class SpinLock { |
| 16 | public: |
| 17 | SpinLock() = default; |
| 18 | |
| 19 | SpinLock(const SpinLock&) = delete; |
| 20 | SpinLock& operator=(const SpinLock&) = delete; |
| 21 | |
| 22 | SpinLock(SpinLock&&) = delete; |
| 23 | SpinLock& operator=(SpinLock&&) = delete; |
| 24 | |
| 25 | void lock(); |
| 26 | void unlock(); |
| 27 | [[nodiscard]] bool try_lock(); |
| 28 | |
| 29 | private: |
| 30 | std::atomic_flag lck = ATOMIC_FLAG_INIT; |
| 31 | }; |
| 32 | |
| 33 | } // namespace Common |
| 34 |