fixup! hle: kernel: Migrate KSession, KClientSession, and KServerSession to KAutoObject.

This commit is contained in:
bunnei 2021-05-01 12:48:41 -07:00
parent 1b074b8984
commit f6d45b747e
3 changed files with 28 additions and 22 deletions

View file

@ -47,11 +47,11 @@ public:
void Initialize(KSession* parent_, std::string&& name_); void Initialize(KSession* parent_, std::string&& name_);
constexpr KSession* GetParent() { KSession* GetParent() {
return parent; return parent;
} }
constexpr const KSession* GetParent() const { const KSession* GetParent() const {
return parent; return parent;
} }

View file

@ -49,24 +49,30 @@ void KSession::Initialize(KClientPort* port_, const std::string& name_) {
} }
void KSession::Finalize() { void KSession::Finalize() {
if (port != nullptr) { if (port == nullptr) {
return;
}
port->OnSessionFinalized(); port->OnSessionFinalized();
port->Close(); port->Close();
}
} }
void KSession::OnServerClosed() { void KSession::OnServerClosed() {
if (GetState() == State::Normal) { if (GetState() != State::Normal) {
return;
}
SetState(State::ServerClosed); SetState(State::ServerClosed);
client.OnServerClosed(); client.OnServerClosed();
}
} }
void KSession::OnClientClosed() { void KSession::OnClientClosed() {
if (GetState() == State::Normal) { if (GetState() != State::Normal) {
return;
}
SetState(State::ClientClosed); SetState(State::ClientClosed);
server.OnClientClosed(); server.OnClientClosed();
}
} }
void KSession::PostDestroy(uintptr_t arg) { void KSession::PostDestroy(uintptr_t arg) {

View file

@ -16,14 +16,6 @@ namespace Kernel {
class KSession final : public KAutoObjectWithSlabHeapAndContainer<KSession, KAutoObjectWithList> { class KSession final : public KAutoObjectWithSlabHeapAndContainer<KSession, KAutoObjectWithList> {
KERNEL_AUTOOBJECT_TRAITS(KSession, KAutoObject); KERNEL_AUTOOBJECT_TRAITS(KSession, KAutoObject);
private:
enum class State : u8 {
Invalid = 0,
Normal = 1,
ClientClosed = 2,
ServerClosed = 3,
};
public: public:
explicit KSession(KernelCore& kernel); explicit KSession(KernelCore& kernel);
virtual ~KSession() override; virtual ~KSession() override;
@ -74,20 +66,28 @@ public:
return port; return port;
} }
private:
enum class State : u8 {
Invalid = 0,
Normal = 1,
ClientClosed = 2,
ServerClosed = 3,
};
private: private:
void SetState(State state) { void SetState(State state) {
atomic_state = static_cast<u8>(state); atomic_state = static_cast<u8>(state);
} }
State GetState() const { State GetState() const {
return static_cast<State>(atomic_state.load()); return static_cast<State>(atomic_state.load(std::memory_order_relaxed));
} }
private: private:
KServerSession server; KServerSession server;
KClientSession client; KClientSession client;
std::atomic<std::underlying_type<State>::type> atomic_state{ std::atomic<std::underlying_type_t<State>> atomic_state{
static_cast<std::underlying_type<State>::type>(State::Invalid)}; static_cast<std::underlying_type_t<State>>(State::Invalid)};
KClientPort* port{}; KClientPort* port{};
KProcess* process{}; KProcess* process{};
bool initialized{}; bool initialized{};