Atmosphere/stratosphere/libstratosphere/source/os/os_waitable_manager.cpp
Michael Scire 609a302e16 os: implement waitable management.
This implements waitable management for Events (and
implements Events). It also refactors PM to use new
Event/Waitable semantics, and also adds STS_ASSERT
as a macro for asserting a boolean expression. The
rest of stratosphere has been refactored to use
STS_ASSERT whenever possible.
2019-12-07 12:41:28 -08:00

90 lines
2.8 KiB
C++

/*
* Copyright (c) 2018-2019 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/>.
*/
#include <stratosphere.hpp>
#include "impl/os_waitable_holder_impl.hpp"
#include "impl/os_waitable_manager_impl.hpp"
namespace sts::os {
WaitableManager::WaitableManager() {
/* Initialize storage. */
new (GetPointer(this->impl_storage)) impl::WaitableManagerImpl();
}
WaitableManager::~WaitableManager() {
auto &impl = GetReference(this->impl_storage);
/* Don't allow destruction of a non-empty waitable holder. */
STS_ASSERT(impl.IsEmpty());
impl.~WaitableManagerImpl();
}
/* Wait. */
WaitableHolder *WaitableManager::WaitAny() {
auto &impl = GetReference(this->impl_storage);
/* Don't allow waiting on empty list. */
STS_ASSERT(!impl.IsEmpty());
return reinterpret_cast<WaitableHolder *>(impl.WaitAny());
}
WaitableHolder *WaitableManager::TryWaitAny() {
auto &impl = GetReference(this->impl_storage);
/* Don't allow waiting on empty list. */
STS_ASSERT(!impl.IsEmpty());
return reinterpret_cast<WaitableHolder *>(impl.TryWaitAny());
}
WaitableHolder *WaitableManager::TimedWaitAny(u64 timeout) {
auto &impl = GetReference(this->impl_storage);
/* Don't allow waiting on empty list. */
STS_ASSERT(!impl.IsEmpty());
return reinterpret_cast<WaitableHolder *>(impl.TimedWaitAny(timeout));
}
/* Link. */
void WaitableManager::LinkWaitableHolder(WaitableHolder *holder) {
auto &impl = GetReference(this->impl_storage);
auto holder_base = reinterpret_cast<impl::WaitableHolderBase *>(GetPointer(holder->impl_storage));
/* Don't allow double-linking a holder. */
STS_ASSERT(!holder_base->IsLinkedToManager());
impl.LinkWaitableHolder(*holder_base);
holder_base->SetManager(&impl);
}
void WaitableManager::UnlinkAll() {
auto &impl = GetReference(this->impl_storage);
impl.UnlinkAll();
}
void WaitableManager::MoveAllFrom(WaitableManager *other) {
auto &dst_impl = GetReference(this->impl_storage);
auto &src_impl = GetReference(other->impl_storage);
dst_impl.MoveAllFrom(src_impl);
}
}