Kernel/ServerSession: Keep track of which threads have issued sync requests.
This commit is contained in:
parent
ac168eeb5d
commit
8feeb81af2
|
@ -39,7 +39,7 @@ ResultCode ClientSession::SendSyncRequest() {
|
||||||
return ERR_SESSION_CLOSED_BY_REMOTE;
|
return ERR_SESSION_CLOSED_BY_REMOTE;
|
||||||
|
|
||||||
// Signal the server session that new data is available
|
// Signal the server session that new data is available
|
||||||
return server->HandleSyncRequest();
|
return server->HandleSyncRequest(GetCurrentThread());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -32,22 +32,29 @@ ResultVal<SharedPtr<ServerSession>> ServerSession::Create(std::string name) {
|
||||||
SharedPtr<ServerSession> server_session(new ServerSession);
|
SharedPtr<ServerSession> server_session(new ServerSession);
|
||||||
|
|
||||||
server_session->name = std::move(name);
|
server_session->name = std::move(name);
|
||||||
server_session->signaled = false;
|
|
||||||
server_session->parent = nullptr;
|
server_session->parent = nullptr;
|
||||||
|
|
||||||
return MakeResult(std::move(server_session));
|
return MakeResult(std::move(server_session));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerSession::ShouldWait(Thread* thread) const {
|
bool ServerSession::ShouldWait(Thread* thread) const {
|
||||||
return !signaled;
|
// Closed sessions should never wait, an error will be returned from svcReplyAndReceive.
|
||||||
|
if (parent->client == nullptr)
|
||||||
|
return false;
|
||||||
|
// Wait if we have no pending requests, or if we're currently handling a request.
|
||||||
|
return pending_requesting_threads.empty() || currently_handling != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerSession::Acquire(Thread* thread) {
|
void ServerSession::Acquire(Thread* thread) {
|
||||||
ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
|
ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
|
||||||
signaled = false;
|
// We are now handling a request, pop it from the stack.
|
||||||
|
// TODO(Subv): What happens if the client endpoint is closed before any requests are made?
|
||||||
|
ASSERT(!pending_requesting_threads.empty());
|
||||||
|
currently_handling = pending_requesting_threads.back();
|
||||||
|
pending_requesting_threads.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ServerSession::HandleSyncRequest() {
|
ResultCode ServerSession::HandleSyncRequest(SharedPtr<Thread> thread) {
|
||||||
// The ServerSession received a sync request, this means that there's new data available
|
// The ServerSession received a sync request, this means that there's new data available
|
||||||
// from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or
|
// from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or
|
||||||
// similar.
|
// similar.
|
||||||
|
@ -60,11 +67,14 @@ ResultCode ServerSession::HandleSyncRequest() {
|
||||||
return result;
|
return result;
|
||||||
hle_handler->HandleSyncRequest(SharedPtr<ServerSession>(this));
|
hle_handler->HandleSyncRequest(SharedPtr<ServerSession>(this));
|
||||||
// TODO(Subv): Translate the response command buffer.
|
// TODO(Subv): Translate the response command buffer.
|
||||||
|
} else {
|
||||||
|
// Add the thread to the list of threads that have issued a sync request with this
|
||||||
|
// server.
|
||||||
|
pending_requesting_threads.push_back(std::move(thread));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this ServerSession does not have an HLE implementation, just wake up the threads waiting
|
// If this ServerSession does not have an HLE implementation, just wake up the threads waiting
|
||||||
// on it.
|
// on it.
|
||||||
signaled = true;
|
|
||||||
WakeupAllWaitingThreads();
|
WakeupAllWaitingThreads();
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -90,4 +100,4 @@ ResultCode TranslateHLERequest(ServerSession* server_session) {
|
||||||
// TODO(Subv): Implement this function once multiple concurrent processes are supported.
|
// TODO(Subv): Implement this function once multiple concurrent processes are supported.
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
} // namespace Kernel
|
||||||
|
|
|
@ -67,20 +67,30 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle a sync request from the emulated application.
|
* Handle a sync request from the emulated application.
|
||||||
|
* @param thread Thread that initiated the request.
|
||||||
* @returns ResultCode from the operation.
|
* @returns ResultCode from the operation.
|
||||||
*/
|
*/
|
||||||
ResultCode HandleSyncRequest();
|
ResultCode HandleSyncRequest(SharedPtr<Thread> thread);
|
||||||
|
|
||||||
bool ShouldWait(Thread* thread) const override;
|
bool ShouldWait(Thread* thread) const override;
|
||||||
|
|
||||||
void Acquire(Thread* thread) override;
|
void Acquire(Thread* thread) override;
|
||||||
|
|
||||||
std::string name; ///< The name of this session (optional)
|
std::string name; ///< The name of this session (optional)
|
||||||
bool signaled; ///< Whether there's new data available to this ServerSession
|
|
||||||
std::shared_ptr<Session> parent; ///< The parent session, which links to the client endpoint.
|
std::shared_ptr<Session> parent; ///< The parent session, which links to the client endpoint.
|
||||||
std::shared_ptr<SessionRequestHandler>
|
std::shared_ptr<SessionRequestHandler>
|
||||||
hle_handler; ///< This session's HLE request handler (optional)
|
hle_handler; ///< This session's HLE request handler (optional)
|
||||||
|
|
||||||
|
/// List of threads that are pending a response after a sync request. This list is processed in
|
||||||
|
/// a LIFO manner, thus, the last request will be dispatched first.
|
||||||
|
/// TODO(Subv): Verify if this is indeed processed in LIFO using a hardware test.
|
||||||
|
std::vector<SharedPtr<Thread>> pending_requesting_threads;
|
||||||
|
|
||||||
|
/// Thread whose request is currently being handled. A request is considered "handled" when a
|
||||||
|
/// response is sent via svcReplyAndReceive.
|
||||||
|
/// TODO(Subv): Find a better name for this.
|
||||||
|
SharedPtr<Thread> currently_handling;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ServerSession();
|
ServerSession();
|
||||||
~ServerSession() override;
|
~ServerSession() override;
|
||||||
|
|
Loading…
Reference in a new issue