1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-23 20:32:10 +00:00
Atmosphere/libraries/libstratosphere/include/stratosphere/os/os_mutex.hpp

75 lines
2.2 KiB
C++
Raw Normal View History

/*
* 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
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:
2020-04-08 10:21:35 +01:00
MutexType mutex;
public:
2020-04-08 10:21:35 +01:00
constexpr explicit Mutex(bool recursive) : mutex{::ams::os::MutexType::State_Initialized, recursive, 0, 0, nullptr, {{0}}} { /* ... */ }
~Mutex() { FinalizeMutex(std::addressof(this->mutex)); }
void lock() {
2020-04-08 10:21:35 +01:00
return LockMutex(std::addressof(this->mutex));
}
void unlock() {
2020-04-08 10:21:35 +01:00
return UnlockMutex(std::addressof(this->mutex));
}
bool try_lock() {
2020-04-08 10:21:35 +01:00
return TryLockMutex(std::addressof(this->mutex));
}
2020-04-08 10:21:35 +01:00
bool IsLockedByCurrentThread() const {
return IsMutexLockedByCurrentThread(std::addressof(this->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 &() {
return this->mutex;
}
2020-04-08 10:21:35 +01:00
operator const MutexType &() const {
return this->mutex;
}
2020-04-08 10:21:35 +01:00
MutexType *GetBase() {
return std::addressof(this->mutex);
}
};
}