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_condition_variable.hpp

66 lines
2.2 KiB
C++
Raw Normal View History

2020-04-08 10:21:35 +01:00
/*
* Copyright (c) Atmosphère-NX
2020-04-08 10:21:35 +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 <vapours.hpp>
#include <stratosphere/os/os_mutex_types.hpp>
#include <stratosphere/os/os_condition_variable_common.hpp>
#include <stratosphere/os/os_condition_variable_types.hpp>
#include <stratosphere/os/os_condition_variable_api.hpp>
namespace ams::os {
class ConditionVariable {
NON_COPYABLE(ConditionVariable);
NON_MOVEABLE(ConditionVariable);
private:
2021-10-10 08:14:06 +01:00
ConditionVariableType m_cv;
2020-04-08 10:21:35 +01:00
public:
constexpr ConditionVariable() : m_cv{::ams::os::ConditionVariableType::State_Initialized, {AMS_OS_INTERNAL_CONDITION_VARIABLE_IMPL_CONSTANT_INITIALIZER}} { /* ... */ }
2020-04-08 10:21:35 +01:00
2021-10-10 08:14:06 +01:00
~ConditionVariable() { FinalizeConditionVariable(std::addressof(m_cv)); }
2020-04-08 10:21:35 +01:00
void Signal() {
2021-10-10 08:14:06 +01:00
SignalConditionVariable(std::addressof(m_cv));
2020-04-08 10:21:35 +01:00
}
void Broadcast() {
2021-10-10 08:14:06 +01:00
BroadcastConditionVariable(std::addressof(m_cv));
2020-04-08 10:21:35 +01:00
}
void Wait(ams::os::MutexType &mutex) {
2021-10-10 08:14:06 +01:00
WaitConditionVariable(std::addressof(m_cv), std::addressof(mutex));
2020-04-08 10:21:35 +01:00
}
ConditionVariableStatus TimedWait(ams::os::MutexType &mutex, TimeSpan timeout) {
2021-10-10 08:14:06 +01:00
return TimedWaitConditionVariable(std::addressof(m_cv), std::addressof(mutex), timeout);
2020-04-08 10:21:35 +01:00
}
operator ConditionVariableType &() {
2021-10-10 08:14:06 +01:00
return m_cv;
2020-04-08 10:21:35 +01:00
}
operator const ConditionVariableType &() const {
2021-10-10 08:14:06 +01:00
return m_cv;
2020-04-08 10:21:35 +01:00
}
ConditionVariableType *GetBase() {
2021-10-10 08:14:06 +01:00
return std::addressof(m_cv);
2020-04-08 10:21:35 +01:00
}
};
}