os: implement BusyMutex
This commit is contained in:
@@ -30,6 +30,8 @@
|
||||
#include <stratosphere/os/os_condition_variable.hpp>
|
||||
#include <stratosphere/os/os_sdk_mutex.hpp>
|
||||
#include <stratosphere/os/os_sdk_condition_variable.hpp>
|
||||
#include <stratosphere/os/os_busy_mutex.hpp>
|
||||
//#include <stratosphere/os/os_rw_busy_mutex.hpp>
|
||||
#include <stratosphere/os/os_rw_lock.hpp>
|
||||
#include <stratosphere/os/os_transfer_memory.hpp>
|
||||
#include <stratosphere/os/os_semaphore.hpp>
|
||||
@@ -42,4 +44,7 @@
|
||||
#include <stratosphere/os/os_sdk_reply_and_receive.hpp>
|
||||
#include <stratosphere/os/os_thread.hpp>
|
||||
#include <stratosphere/os/os_message_queue.hpp>
|
||||
//#include <stratosphere/os/os_light_event.hpp>
|
||||
//#include <stratosphere/os/os_light_message_queue.hpp>
|
||||
//#include <stratosphere/os/os_light_semaphore.hpp>
|
||||
#include <stratosphere/os/os_waitable.hpp>
|
||||
|
||||
@@ -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>;
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 <stratosphere/os/os_busy_mutex_types.hpp>
|
||||
#include <stratosphere/os/os_busy_mutex_api.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class BusyMutex {
|
||||
NON_COPYABLE(BusyMutex);
|
||||
NON_MOVEABLE(BusyMutex);
|
||||
private:
|
||||
BusyMutexType m_mutex;
|
||||
public:
|
||||
constexpr explicit BusyMutex() : m_mutex{::ams::os::BusyMutexType::State_Initialized, nullptr, {{}}} { /* ... */ }
|
||||
|
||||
~BusyMutex() { FinalizeBusyMutex(std::addressof(m_mutex)); }
|
||||
|
||||
void lock() {
|
||||
return LockBusyMutex(std::addressof(m_mutex));
|
||||
}
|
||||
|
||||
void unlock() {
|
||||
return UnlockBusyMutex(std::addressof(m_mutex));
|
||||
}
|
||||
|
||||
bool try_lock() {
|
||||
return TryLockBusyMutex(std::addressof(m_mutex));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void Lock() {
|
||||
return this->lock();
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void Unlock() {
|
||||
return this->unlock();
|
||||
}
|
||||
|
||||
ALWAYS_INLINE bool TryLock() {
|
||||
return this->try_lock();
|
||||
}
|
||||
|
||||
operator BusyMutexType &() {
|
||||
return m_mutex;
|
||||
}
|
||||
|
||||
operator const BusyMutexType &() const {
|
||||
return m_mutex;
|
||||
}
|
||||
|
||||
BusyMutexType *GetBase() {
|
||||
return std::addressof(m_mutex);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 {
|
||||
|
||||
struct BusyMutexType;
|
||||
|
||||
void InitializeBusyMutex(BusyMutexType *mutex);
|
||||
void FinalizeBusyMutex(BusyMutexType *mutex);
|
||||
|
||||
void LockBusyMutex(BusyMutexType *mutex);
|
||||
bool TryLockBusyMutex(BusyMutexType *mutex);
|
||||
void UnlockBusyMutex(BusyMutexType *mutex);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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>
|
||||
#include <stratosphere/os/impl/os_internal_busy_mutex.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct ThreadType;
|
||||
|
||||
struct BusyMutexType {
|
||||
enum State {
|
||||
State_NotInitialized = 0,
|
||||
State_Initialized = 1,
|
||||
};
|
||||
|
||||
u8 state;
|
||||
ThreadType *owner_thread;
|
||||
union {
|
||||
s32 _arr[sizeof(impl::InternalBusyMutexStorage) / sizeof(s32)];
|
||||
impl::InternalBusyMutexStorage _storage;
|
||||
};
|
||||
};
|
||||
static_assert(std::is_trivial<BusyMutexType>::value);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user