Atmosphere/libraries/libstratosphere/include/stratosphere/os/os_sdk_condition_variable.hpp

84 lines
2.7 KiB
C++
Raw Normal View History

2020-10-30 22:36:11 +00:00
/*
* Copyright (c) Atmosphère-NX
2020-10-30 22:36: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 <vapours.hpp>
#include <stratosphere/os/os_sdk_mutex.hpp>
2021-09-29 21:56:53 +00:00
#include <stratosphere/os/os_sdk_recursive_mutex.hpp>
2020-10-30 22:36:11 +00:00
#include <stratosphere/os/impl/os_internal_condition_variable.hpp>
namespace ams::os {
struct SdkConditionVariableType {
union {
s32 _arr[sizeof(impl::InternalConditionVariableStorage) / sizeof(s32)];
impl::InternalConditionVariableStorage _storage;
impl::InternalConditionVariableStorageTypeForConstantInitialize _storage_for_constant_initialize;
2020-10-30 22:36:11 +00:00
};
2021-09-29 21:56:53 +00:00
ALWAYS_INLINE void Initialize() {
2020-10-30 22:36:11 +00:00
GetReference(this->_storage).Initialize();
}
void Wait(SdkMutexType &mutex);
bool TimedWait(SdkMutexType &mutex, TimeSpan timeout);
2021-09-29 21:56:53 +00:00
void Wait(SdkRecursiveMutexType &mutex);
bool TimedWait(SdkRecursiveMutexType &mutex, TimeSpan timeout);
2020-10-30 22:36:11 +00:00
2021-09-29 21:56:53 +00:00
ALWAYS_INLINE void Signal() {
2020-10-30 22:36:11 +00:00
GetReference(this->_storage).Signal();
}
2021-09-29 21:56:53 +00:00
ALWAYS_INLINE void Broadcast() {
2020-10-30 22:36:11 +00:00
GetReference(this->_storage).Broadcast();
}
};
static_assert(std::is_trivial<SdkConditionVariableType>::value);
class SdkConditionVariable {
private:
2021-09-29 21:56:53 +00:00
SdkConditionVariableType m_cv;
2020-10-30 22:36:11 +00:00
public:
constexpr SdkConditionVariable() : m_cv{{AMS_OS_INTERNAL_CONDITION_VARIABLE_IMPL_CONSTANT_INITIALIZER}} { /* ... */ }
2020-10-30 22:36:11 +00:00
2021-09-29 21:56:53 +00:00
ALWAYS_INLINE void Wait(SdkMutex &m) {
return m_cv.Wait(m.m_mutex);
2020-10-30 22:36:11 +00:00
}
2021-09-29 21:56:53 +00:00
ALWAYS_INLINE bool TimedWait(SdkMutex &m, TimeSpan timeout) {
return m_cv.TimedWait(m.m_mutex, timeout);
2020-10-30 22:36:11 +00:00
}
2021-09-29 21:56:53 +00:00
ALWAYS_INLINE void Wait(SdkRecursiveMutex &m) {
return m_cv.Wait(m.m_mutex);
}
ALWAYS_INLINE bool TimedWait(SdkRecursiveMutex &m, TimeSpan timeout) {
return m_cv.TimedWait(m.m_mutex, timeout);
}
2020-10-30 22:36:11 +00:00
2021-09-29 21:56:53 +00:00
ALWAYS_INLINE void Signal() {
return m_cv.Signal();
2020-10-30 22:36:11 +00:00
}
2021-09-29 21:56:53 +00:00
ALWAYS_INLINE void Broadcast() {
return m_cv.Broadcast();
2020-10-30 22:36:11 +00:00
}
};
}