2021-09-29 00:01:11 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2021-09-29 00:01:11 +00:00
|
|
|
*
|
|
|
|
* 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 {
|
|
|
|
|
2021-10-01 18:42:34 +00:00
|
|
|
class ReaderWriterBusyMutex {
|
|
|
|
NON_COPYABLE(ReaderWriterBusyMutex);
|
|
|
|
NON_MOVEABLE(ReaderWriterBusyMutex);
|
2021-09-29 00:01:11 +00:00
|
|
|
private:
|
2021-10-01 18:42:34 +00:00
|
|
|
ReaderWriterBusyMutexType m_rw_mutex;
|
2021-09-29 00:01:11 +00:00
|
|
|
public:
|
2021-10-01 18:42:34 +00:00
|
|
|
constexpr explicit ReaderWriterBusyMutex() : m_rw_mutex{{0}} { /* ... */ }
|
2021-09-29 00:01:11 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-10-01 18:42:34 +00:00
|
|
|
operator ReaderWriterBusyMutexType &() {
|
2021-09-29 00:01:11 +00:00
|
|
|
return m_rw_mutex;
|
|
|
|
}
|
|
|
|
|
2021-10-01 18:42:34 +00:00
|
|
|
operator const ReaderWriterBusyMutexType &() const {
|
2021-09-29 00:01:11 +00:00
|
|
|
return m_rw_mutex;
|
|
|
|
}
|
|
|
|
|
2021-10-01 18:42:34 +00:00
|
|
|
ReaderWriterBusyMutexType *GetBase() {
|
2021-09-29 00:01:11 +00:00
|
|
|
return std::addressof(m_rw_mutex);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|