os: implement BusyMutex

This commit is contained in:
Michael Scire
2021-09-28 14:53:55 -07:00
parent d00cec38b0
commit 09570c470c
9 changed files with 486 additions and 1 deletions

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2018-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 <vapours.hpp>
#if defined(ATMOSPHERE_OS_HORIZON)
#include <stratosphere/os/impl/os_internal_busy_mutex_impl.os.horizon.hpp>
#else
#error "Unknown OS for ams::os::impl::InternalBusyMutexImpl"
#endif
namespace ams::os::impl {
class InternalBusyMutex {
private:
InternalBusyMutexImpl m_impl;
public:
constexpr InternalBusyMutex() : m_impl() { /* ... */ }
constexpr void Initialize() { m_impl.Initialize(); }
constexpr void Finalize() { m_impl.Finalize(); }
bool IsLocked() const { return m_impl.IsLocked(); }
ALWAYS_INLINE void Lock() { return m_impl.Lock(); }
ALWAYS_INLINE bool TryLock() { return m_impl.TryLock(); }
ALWAYS_INLINE void Unlock() { return m_impl.Unlock(); }
ALWAYS_INLINE void lock() { return this->Lock(); }
ALWAYS_INLINE bool try_lock() { return this->TryLock(); }
ALWAYS_INLINE void unlock() { return this->Unlock(); }
};
using InternalBusyMutexStorage = util::TypedStorage<InternalBusyMutex>;
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2018-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 <vapours.hpp>
namespace ams::os::impl {
class InternalBusyMutexImpl {
private:
u32 m_value;
public:
constexpr InternalBusyMutexImpl() : m_value(0) { /* ... */ }
constexpr void Initialize() { m_value = 0; }
constexpr void Finalize() { /* ... */ }
constexpr bool IsLocked() const { return m_value != 0; }
void Lock();
bool TryLock();
void Unlock();
};
}

View File

@@ -38,7 +38,7 @@ namespace ams::os::impl {
constexpr InternalCriticalSectionImpl() : thread_handle(svc::InvalidHandle) { /* ... */ }
constexpr void Initialize() { this->thread_handle = svc::InvalidHandle; }
constexpr void Finalize() { /* ... */}
constexpr void Finalize() { /* ... */ }
void Enter();
bool TryEnter();