diff options
author | Liam <byteslice@airmail.cc> | 2023-02-18 22:26:48 +0100 |
---|---|---|
committer | Liam <byteslice@airmail.cc> | 2023-02-21 18:19:25 +0100 |
commit | a9369726147c7499e0016e183d5d56a7b44efe4b (patch) | |
tree | c1d1b4a9fdafd92863c0922b05d72c14de83ffa7 /src/core/hle/service/mutex.cpp | |
parent | core: defer cpu shutdown (diff) | |
download | yuzu-a9369726147c7499e0016e183d5d56a7b44efe4b.tar yuzu-a9369726147c7499e0016e183d5d56a7b44efe4b.tar.gz yuzu-a9369726147c7499e0016e183d5d56a7b44efe4b.tar.bz2 yuzu-a9369726147c7499e0016e183d5d56a7b44efe4b.tar.lz yuzu-a9369726147c7499e0016e183d5d56a7b44efe4b.tar.xz yuzu-a9369726147c7499e0016e183d5d56a7b44efe4b.tar.zst yuzu-a9369726147c7499e0016e183d5d56a7b44efe4b.zip |
Diffstat (limited to 'src/core/hle/service/mutex.cpp')
-rw-r--r-- | src/core/hle/service/mutex.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/core/hle/service/mutex.cpp b/src/core/hle/service/mutex.cpp new file mode 100644 index 000000000..07589a0f0 --- /dev/null +++ b/src/core/hle/service/mutex.cpp @@ -0,0 +1,43 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/core.h" +#include "core/hle/kernel/k_event.h" +#include "core/hle/kernel/k_synchronization_object.h" +#include "core/hle/service/mutex.h" + +namespace Service { + +Mutex::Mutex(Core::System& system) : m_system(system) { + m_event = Kernel::KEvent::Create(system.Kernel()); + m_event->Initialize(nullptr); + + ASSERT(R_SUCCEEDED(m_event->Signal())); +} + +Mutex::~Mutex() { + m_event->GetReadableEvent().Close(); + m_event->Close(); +} + +void Mutex::lock() { + // Infinitely retry until we successfully clear the event. + while (R_FAILED(m_event->GetReadableEvent().Reset())) { + s32 index; + Kernel::KSynchronizationObject* obj = &m_event->GetReadableEvent(); + + // The event was already cleared! + // Wait for it to become signaled again. + ASSERT(R_SUCCEEDED( + Kernel::KSynchronizationObject::Wait(m_system.Kernel(), &index, &obj, 1, -1))); + } + + // We successfully cleared the event, and now have exclusive ownership. +} + +void Mutex::unlock() { + // Unlock. + ASSERT(R_SUCCEEDED(m_event->Signal())); +} + +} // namespace Service |