os: implement ReadWriteBusyMutex
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
#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_busy_mutex.hpp>
|
||||
#include <stratosphere/os/os_rw_lock.hpp>
|
||||
#include <stratosphere/os/os_transfer_memory.hpp>
|
||||
#include <stratosphere/os/os_semaphore.hpp>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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_rw_busy_mutex_impl.os.horizon.hpp>
|
||||
#else
|
||||
#error "Unknown OS for ams::os::impl::InternalReadWriteBusyMutexImpl"
|
||||
#endif
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class InternalReadWriteBusyMutex {
|
||||
private:
|
||||
InternalReadWriteBusyMutexImpl m_impl;
|
||||
public:
|
||||
constexpr InternalReadWriteBusyMutex() : m_impl() { /* ... */ }
|
||||
|
||||
ALWAYS_INLINE void AcquireReadLock() { return m_impl.AcquireReadLock(); }
|
||||
ALWAYS_INLINE void ReleaseReadLock() { return m_impl.ReleaseReadLock(); }
|
||||
|
||||
ALWAYS_INLINE void AcquireWriteLock() { return m_impl.AcquireWriteLock(); }
|
||||
ALWAYS_INLINE void ReleaseWriteLock() { return m_impl.ReleaseWriteLock(); }
|
||||
};
|
||||
|
||||
using InternalReadWriteBusyMutexStorage = util::TypedStorage<InternalReadWriteBusyMutex>;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 InternalReadWriteBusyMutexImpl {
|
||||
private:
|
||||
u32 m_value;
|
||||
public:
|
||||
constexpr InternalReadWriteBusyMutexImpl() : m_value(0) { /* ... */ }
|
||||
|
||||
constexpr void Initialize() { m_value = 0; }
|
||||
|
||||
void AcquireReadLock();
|
||||
void ReleaseReadLock();
|
||||
|
||||
void AcquireWriteLock();
|
||||
void ReleaseWriteLock();
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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_rw_busy_mutex_types.hpp>
|
||||
#include <stratosphere/os/os_rw_busy_mutex_api.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class ReadWriteBusyMutex {
|
||||
NON_COPYABLE(ReadWriteBusyMutex);
|
||||
NON_MOVEABLE(ReadWriteBusyMutex);
|
||||
private:
|
||||
ReadWriteBusyMutexType m_rw_mutex;
|
||||
public:
|
||||
constexpr explicit ReadWriteBusyMutex() : m_rw_mutex{{0}} { /* ... */ }
|
||||
|
||||
void AcquireReadLock() {
|
||||
return os::AcquireReadLockBusyMutex(std::addressof(m_rw_mutex));
|
||||
}
|
||||
|
||||
void ReleaseReadLock() {
|
||||
return os::ReleaseReadLockBusyMutex(std::addressof(m_rw_mutex));
|
||||
}
|
||||
|
||||
void AcquireWriteLock() {
|
||||
return os::AcquireWriteLockBusyMutex(std::addressof(m_rw_mutex));
|
||||
}
|
||||
|
||||
void ReleaseWriteLock() {
|
||||
return os::ReleaseWriteLockBusyMutex(std::addressof(m_rw_mutex));
|
||||
}
|
||||
|
||||
void lock_shared() {
|
||||
return this->AcquireReadLock();
|
||||
}
|
||||
|
||||
void unlock_shared() {
|
||||
return this->ReleaseReadLock();
|
||||
}
|
||||
|
||||
void lock() {
|
||||
return this->AcquireWriteLock();
|
||||
}
|
||||
|
||||
void unlock() {
|
||||
return this->ReleaseWriteLock();
|
||||
}
|
||||
|
||||
operator ReadWriteBusyMutexType &() {
|
||||
return m_rw_mutex;
|
||||
}
|
||||
|
||||
operator const ReadWriteBusyMutexType &() const {
|
||||
return m_rw_mutex;
|
||||
}
|
||||
|
||||
ReadWriteBusyMutexType *GetBase() {
|
||||
return std::addressof(m_rw_mutex);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 ReadWriteBusyMutexType;
|
||||
|
||||
void InitalizeReadWriteLockBusyMutex(ReadWriteBusyMutexType *rw_mutex);
|
||||
|
||||
void AcquireReadLockBusyMutex(ReadWriteBusyMutexType *rw_mutex);
|
||||
void ReleaseReadLockBusyMutex(ReadWriteBusyMutexType *rw_mutex);
|
||||
|
||||
void AcquireWriteLockBusyMutex(ReadWriteBusyMutexType *rw_mutex);
|
||||
void ReleaseWriteLockBusyMutex(ReadWriteBusyMutexType *rw_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>
|
||||
#include <stratosphere/os/impl/os_internal_rw_busy_mutex.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct ReadWriteBusyMutexType {
|
||||
union {
|
||||
s32 _arr[sizeof(impl::InternalReadWriteBusyMutexStorage) / sizeof(s32)];
|
||||
impl::InternalReadWriteBusyMutexStorage _storage;
|
||||
};
|
||||
};
|
||||
static_assert(std::is_trivial<ReadWriteBusyMutexType>::value);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user