mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-24 19:54:22 -04:00
git subrepo clone https://github.com/Atmosphere-NX/Atmosphere-libs libraries
subrepo: subdir: "libraries" merged: "07af583b" upstream: origin: "https://github.com/Atmosphere-NX/Atmosphere-libs" branch: "master" commit: "07af583b" git-subrepo: version: "0.4.0" origin: "https://github.com/ingydotnet/git-subrepo" commit: "5d6aba9"
This commit is contained in:
parent
28717bfd27
commit
0105455086
294 changed files with 29915 additions and 0 deletions
111
libraries/libstratosphere/source/os/os_interrupt_event.cpp
Normal file
111
libraries/libstratosphere/source/os/os_interrupt_event.cpp
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* 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_object_list.hpp"
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
Result InterruptEvent::Initialize(u32 interrupt_id, bool autoclear) {
|
||||
AMS_ASSERT(!this->is_initialized);
|
||||
this->auto_clear = autoclear;
|
||||
|
||||
const auto type = this->auto_clear ? svc::InterruptType_Edge : svc::InterruptType_Level;
|
||||
R_TRY(svcCreateInterruptEvent(this->handle.GetPointer(), interrupt_id, type));
|
||||
|
||||
this->is_initialized = true;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void InterruptEvent::Finalize() {
|
||||
AMS_ASSERT(this->is_initialized);
|
||||
R_ASSERT(svcCloseHandle(this->handle.Move()));
|
||||
this->auto_clear = true;
|
||||
this->is_initialized = false;
|
||||
}
|
||||
|
||||
InterruptEvent::InterruptEvent(u32 interrupt_id, bool autoclear) {
|
||||
this->is_initialized = false;
|
||||
R_ASSERT(this->Initialize(interrupt_id, autoclear));
|
||||
}
|
||||
|
||||
void InterruptEvent::Reset() {
|
||||
R_ASSERT(svcClearEvent(this->handle.Get()));
|
||||
}
|
||||
|
||||
void InterruptEvent::Wait() {
|
||||
AMS_ASSERT(this->is_initialized);
|
||||
|
||||
while (true) {
|
||||
/* Continuously wait, until success. */
|
||||
R_TRY_CATCH(svcWaitSynchronizationSingle(this->handle.Get(), U64_MAX)) {
|
||||
R_CATCH(svc::ResultCancelled) { continue; }
|
||||
} R_END_TRY_CATCH_WITH_ASSERT;
|
||||
|
||||
/* Clear, if we must. */
|
||||
if (this->auto_clear) {
|
||||
R_TRY_CATCH(svcResetSignal(this->handle.Get())) {
|
||||
/* Some other thread might have caught this before we did. */
|
||||
R_CATCH(svc::ResultInvalidState) { continue; }
|
||||
} R_END_TRY_CATCH_WITH_ASSERT;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool InterruptEvent::TryWait() {
|
||||
AMS_ASSERT(this->is_initialized);
|
||||
|
||||
if (this->auto_clear) {
|
||||
/* Auto-clear. Just try to reset. */
|
||||
return R_SUCCEEDED(svcResetSignal(this->handle.Get()));
|
||||
} else {
|
||||
/* Not auto-clear. */
|
||||
while (true) {
|
||||
/* Continuously wait, until success or timeout. */
|
||||
R_TRY_CATCH(svcWaitSynchronizationSingle(this->handle.Get(), 0)) {
|
||||
R_CATCH(svc::ResultTimedOut) { return false; }
|
||||
R_CATCH(svc::ResultCancelled) { continue; }
|
||||
} R_END_TRY_CATCH_WITH_ASSERT;
|
||||
|
||||
/* We succeeded, so we're signaled. */
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool InterruptEvent::TimedWait(u64 ns) {
|
||||
AMS_ASSERT(this->is_initialized);
|
||||
|
||||
TimeoutHelper timeout_helper(ns);
|
||||
while (true) {
|
||||
/* Continuously wait, until success or timeout. */
|
||||
R_TRY_CATCH(svcWaitSynchronizationSingle(this->handle.Get(), timeout_helper.NsUntilTimeout())) {
|
||||
R_CATCH(svc::ResultTimedOut) { return false; }
|
||||
R_CATCH(svc::ResultCancelled) { continue; }
|
||||
} R_END_TRY_CATCH_WITH_ASSERT;
|
||||
|
||||
/* Clear, if we must. */
|
||||
if (this->auto_clear) {
|
||||
R_TRY_CATCH(svcResetSignal(this->handle.Get())) {
|
||||
/* Some other thread might have caught this before we did. */
|
||||
R_CATCH(svc::ResultInvalidState) { continue; }
|
||||
} R_END_TRY_CATCH_WITH_ASSERT;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue