yuzu/src/core/hle/kernel/k_server_port.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

102 lines
2.4 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2016-05-22 19:30:13 +02:00
#include <tuple>
#include "common/assert.h"
#include "core/hle/kernel/k_client_port.h"
#include "core/hle/kernel/k_port.h"
#include "core/hle/kernel/k_scheduler.h"
#include "core/hle/kernel/k_server_port.h"
#include "core/hle/kernel/k_server_session.h"
#include "core/hle/kernel/k_thread.h"
namespace Kernel {
2023-03-07 16:49:41 +01:00
KServerPort::KServerPort(KernelCore& kernel) : KSynchronizationObject{kernel} {}
KServerPort::~KServerPort() = default;
2023-03-07 02:34:25 +01:00
void KServerPort::Initialize(KPort* parent) {
// Set member variables.
2023-03-07 02:34:25 +01:00
m_parent = parent;
}
bool KServerPort::IsLight() const {
return this->GetParent()->IsLight();
2017-06-23 08:57:05 +02:00
}
void KServerPort::CleanupSessions() {
// Ensure our preconditions are met.
if (this->IsLight()) {
UNIMPLEMENTED();
}
// Cleanup the session list.
while (true) {
// Get the last session in the list
KServerSession* session = nullptr;
{
2023-03-07 16:49:41 +01:00
KScopedSchedulerLock sl{m_kernel};
2023-03-07 02:34:25 +01:00
if (!m_session_list.empty()) {
session = std::addressof(m_session_list.front());
m_session_list.pop_front();
}
}
// Close the session.
if (session != nullptr) {
session->Close();
} else {
break;
}
}
}
void KServerPort::Destroy() {
// Note with our parent that we're closed.
2023-03-07 02:34:25 +01:00
m_parent->OnServerClosed();
// Perform necessary cleanup of our session lists.
this->CleanupSessions();
// Close our reference to our parent.
2023-03-07 02:34:25 +01:00
m_parent->Close();
}
bool KServerPort::IsSignaled() const {
if (this->IsLight()) {
UNIMPLEMENTED();
return false;
} else {
2023-03-07 02:34:25 +01:00
return !m_session_list.empty();
}
}
void KServerPort::EnqueueSession(KServerSession* session) {
ASSERT(!this->IsLight());
2023-03-07 16:49:41 +01:00
KScopedSchedulerLock sl{m_kernel};
// Add the session to our queue.
2023-03-07 02:34:25 +01:00
m_session_list.push_back(*session);
if (m_session_list.size() == 1) {
this->NotifyAvailable();
}
}
KServerSession* KServerPort::AcceptSession() {
ASSERT(!this->IsLight());
2023-03-07 16:49:41 +01:00
KScopedSchedulerLock sl{m_kernel};
// Return the first session in the list.
2023-03-07 02:34:25 +01:00
if (m_session_list.empty()) {
return nullptr;
}
2023-03-07 02:34:25 +01:00
KServerSession* session = std::addressof(m_session_list.front());
m_session_list.pop_front();
return session;
}
} // namespace Kernel