mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
kern: update port/session state semantics
This commit is contained in:
parent
c62a7381f8
commit
cbdf33260e
7 changed files with 32 additions and 11 deletions
|
@ -47,6 +47,7 @@ namespace ams::kern {
|
||||||
ALWAYS_INLINE s32 GetMaxSessions() const { return m_max_sessions; }
|
ALWAYS_INLINE s32 GetMaxSessions() const { return m_max_sessions; }
|
||||||
|
|
||||||
bool IsLight() const;
|
bool IsLight() const;
|
||||||
|
bool IsServerClosed() const;
|
||||||
|
|
||||||
/* Overridden virtual functions. */
|
/* Overridden virtual functions. */
|
||||||
virtual void Destroy() override;
|
virtual void Destroy() override;
|
||||||
|
|
|
@ -47,6 +47,9 @@ namespace ams::kern {
|
||||||
Derived *derived = obj->DynamicCast<Derived *>();
|
Derived *derived = obj->DynamicCast<Derived *>();
|
||||||
R_UNLESS(derived != nullptr, svc::ResultNotFound());
|
R_UNLESS(derived != nullptr, svc::ResultNotFound());
|
||||||
|
|
||||||
|
/* Check that the object is closed. */
|
||||||
|
R_UNLESS(derived->IsServerClosed(), svc::ResultInvalidState());
|
||||||
|
|
||||||
return Delete(obj.GetPointerUnsafe(), name);
|
return Delete(obj.GetPointerUnsafe(), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,11 @@ namespace ams::kern {
|
||||||
uintptr_t GetName() const { return m_name; }
|
uintptr_t GetName() const { return m_name; }
|
||||||
bool IsLight() const { return m_is_light; }
|
bool IsLight() const { return m_is_light; }
|
||||||
|
|
||||||
|
bool IsServerClosed() const {
|
||||||
|
KScopedSchedulerLock sl;
|
||||||
|
return m_state == State::ServerClosed;
|
||||||
|
}
|
||||||
|
|
||||||
Result EnqueueSession(KServerSession *session);
|
Result EnqueueSession(KServerSession *session);
|
||||||
Result EnqueueSession(KLightServerSession *session);
|
Result EnqueueSession(KLightServerSession *session);
|
||||||
|
|
||||||
|
|
|
@ -37,14 +37,22 @@ namespace ams::kern {
|
||||||
private:
|
private:
|
||||||
KServerSession m_server;
|
KServerSession m_server;
|
||||||
KClientSession m_client;
|
KClientSession m_client;
|
||||||
State m_state;
|
std::atomic<std::underlying_type<State>::type> m_atomic_state;
|
||||||
KClientPort *m_port;
|
KClientPort *m_port;
|
||||||
uintptr_t m_name;
|
uintptr_t m_name;
|
||||||
KProcess *m_process;
|
KProcess *m_process;
|
||||||
bool m_initialized;
|
bool m_initialized;
|
||||||
|
private:
|
||||||
|
ALWAYS_INLINE void SetState(State state) {
|
||||||
|
m_atomic_state = static_cast<u8>(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
ALWAYS_INLINE State GetState() const {
|
||||||
|
return static_cast<State>(m_atomic_state.load());
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
constexpr KSession()
|
constexpr KSession()
|
||||||
: m_server(), m_client(), m_state(State::Invalid), m_port(), m_name(), m_process(), m_initialized()
|
: m_server(), m_client(), m_atomic_state(static_cast<std::underlying_type<State>::type>(State::Invalid)), m_port(), m_name(), m_process(), m_initialized()
|
||||||
{
|
{
|
||||||
/* ... */
|
/* ... */
|
||||||
}
|
}
|
||||||
|
@ -62,8 +70,8 @@ namespace ams::kern {
|
||||||
void OnServerClosed();
|
void OnServerClosed();
|
||||||
void OnClientClosed();
|
void OnClientClosed();
|
||||||
|
|
||||||
bool IsServerClosed() const { return m_state != State::Normal; }
|
bool IsServerClosed() const { return this->GetState() != State::Normal; }
|
||||||
bool IsClientClosed() const { return m_state != State::Normal; }
|
bool IsClientClosed() const { return this->GetState() != State::Normal; }
|
||||||
|
|
||||||
Result OnRequest(KSessionRequest *request) { return m_server.OnRequest(request); }
|
Result OnRequest(KSessionRequest *request) { return m_server.OnRequest(request); }
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,10 @@ namespace ams::kern {
|
||||||
return this->GetParent()->IsLight();
|
return this->GetParent()->IsLight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KClientPort::IsServerClosed() const {
|
||||||
|
return this->GetParent()->IsServerClosed();
|
||||||
|
}
|
||||||
|
|
||||||
void KClientPort::Destroy() {
|
void KClientPort::Destroy() {
|
||||||
/* Note with our parent that we're closed. */
|
/* Note with our parent that we're closed. */
|
||||||
m_parent->OnClientClosed();
|
m_parent->OnClientClosed();
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace ams::kern {
|
||||||
KServerSession *session = nullptr;
|
KServerSession *session = nullptr;
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl;
|
KScopedSchedulerLock sl;
|
||||||
while (!m_session_list.empty()) {
|
if (!m_session_list.empty()) {
|
||||||
session = std::addressof(m_session_list.front());
|
session = std::addressof(m_session_list.front());
|
||||||
m_session_list.pop_front();
|
m_session_list.pop_front();
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ namespace ams::kern {
|
||||||
KLightServerSession *session = nullptr;
|
KLightServerSession *session = nullptr;
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl;
|
KScopedSchedulerLock sl;
|
||||||
while (!m_light_session_list.empty()) {
|
if (!m_light_session_list.empty()) {
|
||||||
session = std::addressof(m_light_session_list.front());
|
session = std::addressof(m_light_session_list.front());
|
||||||
m_light_session_list.pop_front();
|
m_light_session_list.pop_front();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace ams::kern {
|
||||||
m_client.Initialize(this);
|
m_client.Initialize(this);
|
||||||
|
|
||||||
/* Set state and name. */
|
/* Set state and name. */
|
||||||
m_state = State::Normal;
|
this->SetState(State::Normal);
|
||||||
m_name = name;
|
m_name = name;
|
||||||
|
|
||||||
/* Set our owner process. */
|
/* Set our owner process. */
|
||||||
|
@ -62,8 +62,8 @@ namespace ams::kern {
|
||||||
void KSession::OnServerClosed() {
|
void KSession::OnServerClosed() {
|
||||||
MESOSPHERE_ASSERT_THIS();
|
MESOSPHERE_ASSERT_THIS();
|
||||||
|
|
||||||
if (m_state == State::Normal) {
|
if (this->GetState() == State::Normal) {
|
||||||
m_state = State::ServerClosed;
|
this->SetState(State::ServerClosed);
|
||||||
m_client.OnServerClosed();
|
m_client.OnServerClosed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,8 +71,8 @@ namespace ams::kern {
|
||||||
void KSession::OnClientClosed() {
|
void KSession::OnClientClosed() {
|
||||||
MESOSPHERE_ASSERT_THIS();
|
MESOSPHERE_ASSERT_THIS();
|
||||||
|
|
||||||
if (m_state == State::Normal) {
|
if (this->GetState() == State::Normal) {
|
||||||
m_state = State::ClientClosed;
|
this->SetState(State::ClientClosed);
|
||||||
m_server.OnClientClosed();
|
m_server.OnClientClosed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue