kern: update port/session state semantics
This commit is contained in:
@@ -47,6 +47,7 @@ namespace ams::kern {
|
||||
ALWAYS_INLINE s32 GetMaxSessions() const { return m_max_sessions; }
|
||||
|
||||
bool IsLight() const;
|
||||
bool IsServerClosed() const;
|
||||
|
||||
/* Overridden virtual functions. */
|
||||
virtual void Destroy() override;
|
||||
|
||||
@@ -47,6 +47,9 @@ namespace ams::kern {
|
||||
Derived *derived = obj->DynamicCast<Derived *>();
|
||||
R_UNLESS(derived != nullptr, svc::ResultNotFound());
|
||||
|
||||
/* Check that the object is closed. */
|
||||
R_UNLESS(derived->IsServerClosed(), svc::ResultInvalidState());
|
||||
|
||||
return Delete(obj.GetPointerUnsafe(), name);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,11 @@ namespace ams::kern {
|
||||
uintptr_t GetName() const { return m_name; }
|
||||
bool IsLight() const { return m_is_light; }
|
||||
|
||||
bool IsServerClosed() const {
|
||||
KScopedSchedulerLock sl;
|
||||
return m_state == State::ServerClosed;
|
||||
}
|
||||
|
||||
Result EnqueueSession(KServerSession *session);
|
||||
Result EnqueueSession(KLightServerSession *session);
|
||||
|
||||
|
||||
@@ -37,14 +37,22 @@ namespace ams::kern {
|
||||
private:
|
||||
KServerSession m_server;
|
||||
KClientSession m_client;
|
||||
State m_state;
|
||||
std::atomic<std::underlying_type<State>::type> m_atomic_state;
|
||||
KClientPort *m_port;
|
||||
uintptr_t m_name;
|
||||
KProcess *m_process;
|
||||
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:
|
||||
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 OnClientClosed();
|
||||
|
||||
bool IsServerClosed() const { return m_state != State::Normal; }
|
||||
bool IsClientClosed() const { return m_state != State::Normal; }
|
||||
bool IsServerClosed() const { return this->GetState() != State::Normal; }
|
||||
bool IsClientClosed() const { return this->GetState() != State::Normal; }
|
||||
|
||||
Result OnRequest(KSessionRequest *request) { return m_server.OnRequest(request); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user