2019-09-28 01:04:58 +00:00
|
|
|
/*
|
|
|
|
* 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 "impl/os_waitable_holder_impl.hpp"
|
|
|
|
#include "impl/os_waitable_manager_impl.hpp"
|
|
|
|
|
2019-10-24 09:30:10 +00:00
|
|
|
namespace ams::os {
|
2019-09-28 01:04:58 +00:00
|
|
|
|
|
|
|
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. */
|
2019-10-24 09:30:10 +00:00
|
|
|
AMS_ASSERT(impl.IsEmpty());
|
2019-09-28 01:04:58 +00:00
|
|
|
|
|
|
|
impl.~WaitableManagerImpl();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Wait. */
|
|
|
|
WaitableHolder *WaitableManager::WaitAny() {
|
|
|
|
auto &impl = GetReference(this->impl_storage);
|
|
|
|
|
|
|
|
/* Don't allow waiting on empty list. */
|
2019-10-24 09:30:10 +00:00
|
|
|
AMS_ASSERT(!impl.IsEmpty());
|
2019-09-28 01:04:58 +00:00
|
|
|
|
|
|
|
return reinterpret_cast<WaitableHolder *>(impl.WaitAny());
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitableHolder *WaitableManager::TryWaitAny() {
|
|
|
|
auto &impl = GetReference(this->impl_storage);
|
|
|
|
|
|
|
|
/* Don't allow waiting on empty list. */
|
2019-10-24 09:30:10 +00:00
|
|
|
AMS_ASSERT(!impl.IsEmpty());
|
2019-09-28 01:04:58 +00:00
|
|
|
|
|
|
|
return reinterpret_cast<WaitableHolder *>(impl.TryWaitAny());
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitableHolder *WaitableManager::TimedWaitAny(u64 timeout) {
|
|
|
|
auto &impl = GetReference(this->impl_storage);
|
|
|
|
|
|
|
|
/* Don't allow waiting on empty list. */
|
2019-10-24 09:30:10 +00:00
|
|
|
AMS_ASSERT(!impl.IsEmpty());
|
2019-09-28 01:04:58 +00:00
|
|
|
|
|
|
|
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. */
|
2019-10-24 09:30:10 +00:00
|
|
|
AMS_ASSERT(!holder_base->IsLinkedToManager());
|
2019-09-28 01:04:58 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|