1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-27 04:36:04 +00:00
Atmosphere/libraries/libstratosphere/include/stratosphere/os/os_busy_mutex.hpp

70 lines
2.1 KiB
C++
Raw Normal View History

2021-09-28 22:53:55 +01:00
/*
* Copyright (c) Atmosphère-NX
2021-09-28 22:53:55 +01: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_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, {{AMS_OS_INTERNAL_BUSY_MUTEX_IMPL_CONSTANT_INITIALIZE_ARRAY_VALUES}}} { /* ... */ }
2021-09-28 22:53:55 +01:00
~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);
}
};
}