1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-24 04:42:11 +00:00
Atmosphere/libraries/libstratosphere/include/stratosphere/os/os_mutex.hpp

75 lines
2.2 KiB
C++
Raw Normal View History

/*
* Copyright (c) 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
2020-04-08 10:21:35 +01:00
#include <stratosphere/os/os_mutex_common.hpp>
#include <stratosphere/os/os_mutex_types.hpp>
#include <stratosphere/os/os_mutex_api.hpp>
namespace ams::os {
class Mutex {
NON_COPYABLE(Mutex);
NON_MOVEABLE(Mutex);
private:
2021-10-10 08:14:06 +01:00
MutexType m_mutex;
public:
constexpr explicit Mutex(bool recursive) : m_mutex{::ams::os::MutexType::State_Initialized, recursive, 0, 0, nullptr, { AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CONSTANT_INITIALIZER } } { /* ... */ }
2020-04-08 10:21:35 +01:00
2021-10-10 08:14:06 +01:00
~Mutex() { FinalizeMutex(std::addressof(m_mutex)); }
void lock() {
2021-10-10 08:14:06 +01:00
return LockMutex(std::addressof(m_mutex));
}
void unlock() {
2021-10-10 08:14:06 +01:00
return UnlockMutex(std::addressof(m_mutex));
}
bool try_lock() {
2021-10-10 08:14:06 +01:00
return TryLockMutex(std::addressof(m_mutex));
}
2020-04-08 10:21:35 +01:00
bool IsLockedByCurrentThread() const {
2021-10-10 08:14:06 +01:00
return IsMutexLockedByCurrentThread(std::addressof(m_mutex));
}
2020-04-08 10:21:35 +01:00
ALWAYS_INLINE void Lock() {
return this->lock();
}
2020-04-08 10:21:35 +01:00
ALWAYS_INLINE void Unlock() {
return this->unlock();
}
2020-04-08 10:21:35 +01:00
ALWAYS_INLINE bool TryLock() {
return this->try_lock();
}
2020-04-08 10:21:35 +01:00
operator MutexType &() {
2021-10-10 08:14:06 +01:00
return m_mutex;
}
2020-04-08 10:21:35 +01:00
operator const MutexType &() const {
2021-10-10 08:14:06 +01:00
return m_mutex;
}
2020-04-08 10:21:35 +01:00
MutexType *GetBase() {
2021-10-10 08:14:06 +01:00
return std::addressof(m_mutex);
}
};
}