1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-19 00:42:06 +00:00
Atmosphere/thermosphere/src/hvisor_synchronization.hpp

63 lines
1.6 KiB
C++

/*
* Copyright (c) 2019-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "defines.hpp"
namespace ams::hvisor {
class Spinlock final {
NON_COPYABLE(Spinlock);
NON_MOVEABLE(Spinlock);
private:
u32 m_val = 0;
public:
constexpr Spinlock() = default;
void lock();
void unlock() noexcept;
};
class Barrier final {
NON_COPYABLE(Barrier);
NON_MOVEABLE(Barrier);
private:
u32 m_val = 0;
public:
constexpr Barrier() = default;
void Join();
constexpr void Reset(u32 val)
{
m_val = val;
}
};
class RecursiveSpinlock final {
NON_COPYABLE(RecursiveSpinlock);
NON_MOVEABLE(RecursiveSpinlock);
private:
Spinlock m_spinlock{};
u32 m_tag = 0;
u32 m_count = 0;
public:
constexpr RecursiveSpinlock() = default;
void lock();
void unlock() noexcept;
};
}