Seregon/ShadPKG

A tool for deriving PKG packet encryption keys for ps4 written in c++

C++/47.3 KB/No license
common/spin_lock.h
ShadPKG / common / spin_lock.h
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 
8namespace 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 */
15class SpinLock {
16public:
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 
29private:
30 std::atomic_flag lck = ATOMIC_FLAG_INIT;
31};
32 
33} // namespace Common
34