2019-12-09 11:57:37 +00:00
|
|
|
/*
|
2020-01-24 10:10:40 +00:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2019-12-09 11:57:37 +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/>.
|
|
|
|
*/
|
2020-05-11 22:02:10 +00:00
|
|
|
#include <stratosphere.hpp>
|
2020-04-08 09:21:35 +00:00
|
|
|
#include "impl/os_interrupt_event_impl.hpp"
|
2021-10-01 02:00:47 +00:00
|
|
|
#include "impl/os_multiple_wait_holder_impl.hpp"
|
|
|
|
#include "impl/os_multiple_wait_object_list.hpp"
|
2019-12-09 11:57:37 +00:00
|
|
|
|
|
|
|
namespace ams::os {
|
|
|
|
|
2020-04-08 09:21:35 +00:00
|
|
|
void InitializeInterruptEvent(InterruptEventType *event, InterruptName name, EventClearMode clear_mode) {
|
|
|
|
/* Initialize member variables. */
|
|
|
|
event->clear_mode = static_cast<u8>(clear_mode);
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2020-04-08 09:21:35 +00:00
|
|
|
/* Initialize implementation. */
|
2021-03-22 03:30:40 +00:00
|
|
|
util::ConstructAt(event->impl, name, clear_mode);
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2020-04-08 09:21:35 +00:00
|
|
|
/* Mark initialized. */
|
|
|
|
event->state = InterruptEventType::State_Initialized;
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 09:21:35 +00:00
|
|
|
void FinalizeInterruptEvent(InterruptEventType *event) {
|
|
|
|
AMS_ASSERT(event->state == InterruptEventType::State_Initialized);
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2020-04-08 09:21:35 +00:00
|
|
|
/* Mark uninitialized. */
|
|
|
|
event->state = InterruptEventType::State_NotInitialized;
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2020-04-08 09:21:35 +00:00
|
|
|
/* Destroy objects. */
|
2021-03-22 03:30:40 +00:00
|
|
|
util::DestroyAt(event->impl);
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 09:21:35 +00:00
|
|
|
void WaitInterruptEvent(InterruptEventType *event) {
|
|
|
|
AMS_ASSERT(event->state == InterruptEventType::State_Initialized);
|
|
|
|
return GetReference(event->impl).Wait();
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 09:21:35 +00:00
|
|
|
bool TryWaitInterruptEvent(InterruptEventType *event) {
|
|
|
|
AMS_ASSERT(event->state == InterruptEventType::State_Initialized);
|
|
|
|
return GetReference(event->impl).TryWait();
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 09:21:35 +00:00
|
|
|
bool TimedWaitInterruptEvent(InterruptEventType *event, TimeSpan timeout) {
|
|
|
|
AMS_ASSERT(event->state == InterruptEventType::State_Initialized);
|
|
|
|
AMS_ASSERT(timeout.GetNanoSeconds() >= 0);
|
|
|
|
return GetReference(event->impl).TimedWait(timeout);
|
|
|
|
}
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2020-04-08 09:21:35 +00:00
|
|
|
void ClearInterruptEvent(InterruptEventType *event) {
|
|
|
|
AMS_ASSERT(event->state == InterruptEventType::State_Initialized);
|
|
|
|
return GetReference(event->impl).Clear();
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2021-10-01 02:00:47 +00:00
|
|
|
void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, InterruptEventType *event) {
|
2020-10-31 10:22:01 +00:00
|
|
|
AMS_ASSERT(event->state == InterruptEventType::State_Initialized);
|
|
|
|
|
2021-10-01 02:00:47 +00:00
|
|
|
util::ConstructAt(GetReference(multi_wait_holder->impl_storage).holder_of_interrupt_event_storage, event);
|
2020-10-31 10:22:01 +00:00
|
|
|
|
2021-10-01 02:00:47 +00:00
|
|
|
multi_wait_holder->user_data = 0;
|
2020-10-31 10:22:01 +00:00
|
|
|
}
|
|
|
|
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|