summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2021-05-01 12:48:41 -0700
committerGravatar bunnei2021-05-05 16:40:53 -0700
commitf6d45b747e37ed1871d9155fbf2d3d5099e1c1b8 (patch)
tree6cbdec08fa1006a4fd9ba21a6fe9a97ba8b47e81 /src
parentfixup! hle: kernel: Migrate KSession, KClientSession, and KServerSession to K... (diff)
downloadyuzu-f6d45b747e37ed1871d9155fbf2d3d5099e1c1b8.tar.gz
yuzu-f6d45b747e37ed1871d9155fbf2d3d5099e1c1b8.tar.xz
yuzu-f6d45b747e37ed1871d9155fbf2d3d5099e1c1b8.zip
fixup! hle: kernel: Migrate KSession, KClientSession, and KServerSession to KAutoObject.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/k_server_session.h4
-rw-r--r--src/core/hle/kernel/k_session.cpp24
-rw-r--r--src/core/hle/kernel/k_session.h22
3 files changed, 28 insertions, 22 deletions
diff --git a/src/core/hle/kernel/k_server_session.h b/src/core/hle/kernel/k_server_session.h
index 4a54e6634..77095bb85 100644
--- a/src/core/hle/kernel/k_server_session.h
+++ b/src/core/hle/kernel/k_server_session.h
@@ -47,11 +47,11 @@ public:
47 47
48 void Initialize(KSession* parent_, std::string&& name_); 48 void Initialize(KSession* parent_, std::string&& name_);
49 49
50 constexpr KSession* GetParent() { 50 KSession* GetParent() {
51 return parent; 51 return parent;
52 } 52 }
53 53
54 constexpr const KSession* GetParent() const { 54 const KSession* GetParent() const {
55 return parent; 55 return parent;
56 } 56 }
57 57
diff --git a/src/core/hle/kernel/k_session.cpp b/src/core/hle/kernel/k_session.cpp
index 5e629d446..7b0bc177d 100644
--- a/src/core/hle/kernel/k_session.cpp
+++ b/src/core/hle/kernel/k_session.cpp
@@ -49,24 +49,30 @@ void KSession::Initialize(KClientPort* port_, const std::string& name_) {
49} 49}
50 50
51void KSession::Finalize() { 51void KSession::Finalize() {
52 if (port != nullptr) { 52 if (port == nullptr) {
53 port->OnSessionFinalized(); 53 return;
54 port->Close();
55 } 54 }
55
56 port->OnSessionFinalized();
57 port->Close();
56} 58}
57 59
58void KSession::OnServerClosed() { 60void KSession::OnServerClosed() {
59 if (GetState() == State::Normal) { 61 if (GetState() != State::Normal) {
60 SetState(State::ServerClosed); 62 return;
61 client.OnServerClosed();
62 } 63 }
64
65 SetState(State::ServerClosed);
66 client.OnServerClosed();
63} 67}
64 68
65void KSession::OnClientClosed() { 69void KSession::OnClientClosed() {
66 if (GetState() == State::Normal) { 70 if (GetState() != State::Normal) {
67 SetState(State::ClientClosed); 71 return;
68 server.OnClientClosed();
69 } 72 }
73
74 SetState(State::ClientClosed);
75 server.OnClientClosed();
70} 76}
71 77
72void KSession::PostDestroy(uintptr_t arg) { 78void KSession::PostDestroy(uintptr_t arg) {
diff --git a/src/core/hle/kernel/k_session.h b/src/core/hle/kernel/k_session.h
index d50e21f3f..4321b7885 100644
--- a/src/core/hle/kernel/k_session.h
+++ b/src/core/hle/kernel/k_session.h
@@ -16,14 +16,6 @@ namespace Kernel {
16class KSession final : public KAutoObjectWithSlabHeapAndContainer<KSession, KAutoObjectWithList> { 16class KSession final : public KAutoObjectWithSlabHeapAndContainer<KSession, KAutoObjectWithList> {
17 KERNEL_AUTOOBJECT_TRAITS(KSession, KAutoObject); 17 KERNEL_AUTOOBJECT_TRAITS(KSession, KAutoObject);
18 18
19private:
20 enum class State : u8 {
21 Invalid = 0,
22 Normal = 1,
23 ClientClosed = 2,
24 ServerClosed = 3,
25 };
26
27public: 19public:
28 explicit KSession(KernelCore& kernel); 20 explicit KSession(KernelCore& kernel);
29 virtual ~KSession() override; 21 virtual ~KSession() override;
@@ -75,19 +67,27 @@ public:
75 } 67 }
76 68
77private: 69private:
70 enum class State : u8 {
71 Invalid = 0,
72 Normal = 1,
73 ClientClosed = 2,
74 ServerClosed = 3,
75 };
76
77private:
78 void SetState(State state) { 78 void SetState(State state) {
79 atomic_state = static_cast<u8>(state); 79 atomic_state = static_cast<u8>(state);
80 } 80 }
81 81
82 State GetState() const { 82 State GetState() const {
83 return static_cast<State>(atomic_state.load()); 83 return static_cast<State>(atomic_state.load(std::memory_order_relaxed));
84 } 84 }
85 85
86private: 86private:
87 KServerSession server; 87 KServerSession server;
88 KClientSession client; 88 KClientSession client;
89 std::atomic<std::underlying_type<State>::type> atomic_state{ 89 std::atomic<std::underlying_type_t<State>> atomic_state{
90 static_cast<std::underlying_type<State>::type>(State::Invalid)}; 90 static_cast<std::underlying_type_t<State>>(State::Invalid)};
91 KClientPort* port{}; 91 KClientPort* port{};
92 KProcess* process{}; 92 KProcess* process{};
93 bool initialized{}; 93 bool initialized{};