mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-09-09 14:29:08 +01:00
Kernel: Added ClientPort and ServerPort classes.
This is part of an ongoing effort to implement support for multiple processes.
This commit is contained in:
parent
8df4283b19
commit
3d9fbffbab
6 changed files with 139 additions and 2 deletions
|
@ -29,6 +29,7 @@ set(SRCS
|
||||||
hle/applets/mii_selector.cpp
|
hle/applets/mii_selector.cpp
|
||||||
hle/applets/swkbd.cpp
|
hle/applets/swkbd.cpp
|
||||||
hle/kernel/address_arbiter.cpp
|
hle/kernel/address_arbiter.cpp
|
||||||
|
hle/kernel/client_port.cpp
|
||||||
hle/kernel/event.cpp
|
hle/kernel/event.cpp
|
||||||
hle/kernel/kernel.cpp
|
hle/kernel/kernel.cpp
|
||||||
hle/kernel/memory.cpp
|
hle/kernel/memory.cpp
|
||||||
|
@ -36,6 +37,7 @@ set(SRCS
|
||||||
hle/kernel/process.cpp
|
hle/kernel/process.cpp
|
||||||
hle/kernel/resource_limit.cpp
|
hle/kernel/resource_limit.cpp
|
||||||
hle/kernel/semaphore.cpp
|
hle/kernel/semaphore.cpp
|
||||||
|
hle/kernel/server_port.cpp
|
||||||
hle/kernel/session.cpp
|
hle/kernel/session.cpp
|
||||||
hle/kernel/shared_memory.cpp
|
hle/kernel/shared_memory.cpp
|
||||||
hle/kernel/thread.cpp
|
hle/kernel/thread.cpp
|
||||||
|
@ -164,6 +166,7 @@ set(HEADERS
|
||||||
hle/applets/mii_selector.h
|
hle/applets/mii_selector.h
|
||||||
hle/applets/swkbd.h
|
hle/applets/swkbd.h
|
||||||
hle/kernel/address_arbiter.h
|
hle/kernel/address_arbiter.h
|
||||||
|
hle/kernel/client_port.h
|
||||||
hle/kernel/event.h
|
hle/kernel/event.h
|
||||||
hle/kernel/kernel.h
|
hle/kernel/kernel.h
|
||||||
hle/kernel/memory.h
|
hle/kernel/memory.h
|
||||||
|
@ -171,6 +174,7 @@ set(HEADERS
|
||||||
hle/kernel/process.h
|
hle/kernel/process.h
|
||||||
hle/kernel/resource_limit.h
|
hle/kernel/resource_limit.h
|
||||||
hle/kernel/semaphore.h
|
hle/kernel/semaphore.h
|
||||||
|
hle/kernel/server_port.h
|
||||||
hle/kernel/session.h
|
hle/kernel/session.h
|
||||||
hle/kernel/shared_memory.h
|
hle/kernel/shared_memory.h
|
||||||
hle/kernel/thread.h
|
hle/kernel/thread.h
|
||||||
|
|
16
src/core/hle/kernel/client_port.cpp
Normal file
16
src/core/hle/kernel/client_port.cpp
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// Copyright 2016 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "common/assert.h"
|
||||||
|
|
||||||
|
#include "core/hle/kernel/client_port.h"
|
||||||
|
#include "core/hle/kernel/kernel.h"
|
||||||
|
#include "core/hle/kernel/server_port.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
ClientPort::ClientPort() {}
|
||||||
|
ClientPort::~ClientPort() {}
|
||||||
|
|
||||||
|
} // namespace
|
34
src/core/hle/kernel/client_port.h
Normal file
34
src/core/hle/kernel/client_port.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright 2016 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "common/common_types.h"
|
||||||
|
|
||||||
|
#include "core/hle/kernel/kernel.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
class ClientPort : public Object {
|
||||||
|
public:
|
||||||
|
friend class ServerPort;
|
||||||
|
std::string GetTypeName() const override { return "ClientPort"; }
|
||||||
|
std::string GetName() const override { return name; }
|
||||||
|
|
||||||
|
static const HandleType HANDLE_TYPE = HandleType::ClientPort;
|
||||||
|
HandleType GetHandleType() const override { return HANDLE_TYPE; }
|
||||||
|
|
||||||
|
SharedPtr<ServerPort> server_port; ///< ServerPort associated with this client port.
|
||||||
|
u32 max_sessions; ///< Maximum number of simultaneous sessions the port can have
|
||||||
|
u32 active_sessions; ///< Number of currently open sessions to this port
|
||||||
|
std::string name; ///< Name of client port (optional)
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ClientPort();
|
||||||
|
~ClientPort() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
|
@ -35,7 +35,7 @@ enum KernelHandle : Handle {
|
||||||
|
|
||||||
enum class HandleType : u32 {
|
enum class HandleType : u32 {
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
Port = 1,
|
ServerPort = 1,
|
||||||
Session = 2,
|
Session = 2,
|
||||||
Event = 3,
|
Event = 3,
|
||||||
Mutex = 4,
|
Mutex = 4,
|
||||||
|
@ -48,6 +48,7 @@ enum class HandleType : u32 {
|
||||||
Timer = 11,
|
Timer = 11,
|
||||||
ResourceLimit = 12,
|
ResourceLimit = 12,
|
||||||
CodeSet = 13,
|
CodeSet = 13,
|
||||||
|
ClientPort = 14,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -72,6 +73,7 @@ public:
|
||||||
bool IsWaitable() const {
|
bool IsWaitable() const {
|
||||||
switch (GetHandleType()) {
|
switch (GetHandleType()) {
|
||||||
case HandleType::Session:
|
case HandleType::Session:
|
||||||
|
case HandleType::ServerPort:
|
||||||
case HandleType::Event:
|
case HandleType::Event:
|
||||||
case HandleType::Mutex:
|
case HandleType::Mutex:
|
||||||
case HandleType::Thread:
|
case HandleType::Thread:
|
||||||
|
@ -80,13 +82,13 @@ public:
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case HandleType::Unknown:
|
case HandleType::Unknown:
|
||||||
case HandleType::Port:
|
|
||||||
case HandleType::SharedMemory:
|
case HandleType::SharedMemory:
|
||||||
case HandleType::Redirection:
|
case HandleType::Redirection:
|
||||||
case HandleType::Process:
|
case HandleType::Process:
|
||||||
case HandleType::AddressArbiter:
|
case HandleType::AddressArbiter:
|
||||||
case HandleType::ResourceLimit:
|
case HandleType::ResourceLimit:
|
||||||
case HandleType::CodeSet:
|
case HandleType::CodeSet:
|
||||||
|
case HandleType::ClientPort:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
38
src/core/hle/kernel/server_port.cpp
Normal file
38
src/core/hle/kernel/server_port.cpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
// Copyright 2016 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "common/assert.h"
|
||||||
|
|
||||||
|
#include "core/hle/kernel/kernel.h"
|
||||||
|
#include "core/hle/kernel/server_port.h"
|
||||||
|
#include "core/hle/kernel/thread.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
ServerPort::ServerPort() {}
|
||||||
|
ServerPort::~ServerPort() {}
|
||||||
|
|
||||||
|
bool ServerPort::ShouldWait() {
|
||||||
|
// If there are no pending sessions, we wait until a new one is added.
|
||||||
|
return pending_sessions.size() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerPort::Acquire() {
|
||||||
|
ASSERT_MSG(!ShouldWait(), "object unavailable!");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> ServerPort::CreatePortPair(u32 max_sessions, std::string name) {
|
||||||
|
SharedPtr<ServerPort> server_port(new ServerPort);
|
||||||
|
SharedPtr<ClientPort> client_port(new ClientPort);
|
||||||
|
|
||||||
|
server_port->name = name + "_Server";
|
||||||
|
client_port->name = name + "_Client";
|
||||||
|
client_port->server_port = server_port;
|
||||||
|
client_port->max_sessions = max_sessions;
|
||||||
|
client_port->active_sessions = 0;
|
||||||
|
|
||||||
|
return std::make_tuple(std::move(server_port), std::move(client_port));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
43
src/core/hle/kernel/server_port.h
Normal file
43
src/core/hle/kernel/server_port.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
// Copyright 2016 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "common/common_types.h"
|
||||||
|
|
||||||
|
#include "core/hle/kernel/kernel.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
class ServerPort final : public WaitObject {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Creates a pair of a ServerPort and an associated ClientPort.
|
||||||
|
* @param max_sessions Maximum number of sessions to the port
|
||||||
|
* @param name Optional name of the ports
|
||||||
|
* @return The created port tuple
|
||||||
|
*/
|
||||||
|
static std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> CreatePortPair(u32 max_sessions, std::string name = "UnknownPort");
|
||||||
|
|
||||||
|
std::string GetTypeName() const override { return "ServerPort"; }
|
||||||
|
std::string GetName() const override { return name; }
|
||||||
|
|
||||||
|
static const HandleType HANDLE_TYPE = HandleType::ServerPort;
|
||||||
|
HandleType GetHandleType() const override { return HANDLE_TYPE; }
|
||||||
|
|
||||||
|
std::string name; ///< Name of port (optional)
|
||||||
|
|
||||||
|
std::vector<SharedPtr<WaitObject>> pending_sessions; ///< ServerSessions waiting to be accepted by the port
|
||||||
|
|
||||||
|
bool ShouldWait() override;
|
||||||
|
void Acquire() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ServerPort();
|
||||||
|
~ServerPort() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
Loading…
Reference in a new issue