diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/client_session.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/server_session.cpp | 22 | ||||
| -rw-r--r-- | src/core/hle/kernel/server_session.h | 14 |
3 files changed, 29 insertions, 9 deletions
diff --git a/src/core/hle/kernel/client_session.cpp b/src/core/hle/kernel/client_session.cpp index fef97af1f..78a64d105 100644 --- a/src/core/hle/kernel/client_session.cpp +++ b/src/core/hle/kernel/client_session.cpp | |||
| @@ -39,7 +39,7 @@ ResultCode ClientSession::SendSyncRequest() { | |||
| 39 | return ERR_SESSION_CLOSED_BY_REMOTE; | 39 | return ERR_SESSION_CLOSED_BY_REMOTE; |
| 40 | 40 | ||
| 41 | // Signal the server session that new data is available | 41 | // Signal the server session that new data is available |
| 42 | return server->HandleSyncRequest(); | 42 | return server->HandleSyncRequest(GetCurrentThread()); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | } // namespace | 45 | } // namespace |
diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp index 2dc709bc9..970eac5fe 100644 --- a/src/core/hle/kernel/server_session.cpp +++ b/src/core/hle/kernel/server_session.cpp | |||
| @@ -32,22 +32,29 @@ ResultVal<SharedPtr<ServerSession>> ServerSession::Create(std::string name) { | |||
| 32 | SharedPtr<ServerSession> server_session(new ServerSession); | 32 | SharedPtr<ServerSession> server_session(new ServerSession); |
| 33 | 33 | ||
| 34 | server_session->name = std::move(name); | 34 | server_session->name = std::move(name); |
| 35 | server_session->signaled = false; | ||
| 36 | server_session->parent = nullptr; | 35 | server_session->parent = nullptr; |
| 37 | 36 | ||
| 38 | return MakeResult(std::move(server_session)); | 37 | return MakeResult(std::move(server_session)); |
| 39 | } | 38 | } |
| 40 | 39 | ||
| 41 | bool ServerSession::ShouldWait(Thread* thread) const { | 40 | bool ServerSession::ShouldWait(Thread* thread) const { |
| 42 | return !signaled; | 41 | // Closed sessions should never wait, an error will be returned from svcReplyAndReceive. |
| 42 | if (parent->client == nullptr) | ||
| 43 | return false; | ||
| 44 | // Wait if we have no pending requests, or if we're currently handling a request. | ||
| 45 | return pending_requesting_threads.empty() || currently_handling != nullptr; | ||
| 43 | } | 46 | } |
| 44 | 47 | ||
| 45 | void ServerSession::Acquire(Thread* thread) { | 48 | void ServerSession::Acquire(Thread* thread) { |
| 46 | ASSERT_MSG(!ShouldWait(thread), "object unavailable!"); | 49 | ASSERT_MSG(!ShouldWait(thread), "object unavailable!"); |
| 47 | signaled = false; | 50 | // We are now handling a request, pop it from the stack. |
| 51 | // TODO(Subv): What happens if the client endpoint is closed before any requests are made? | ||
| 52 | ASSERT(!pending_requesting_threads.empty()); | ||
| 53 | currently_handling = pending_requesting_threads.back(); | ||
| 54 | pending_requesting_threads.pop_back(); | ||
| 48 | } | 55 | } |
| 49 | 56 | ||
| 50 | ResultCode ServerSession::HandleSyncRequest() { | 57 | ResultCode ServerSession::HandleSyncRequest(SharedPtr<Thread> thread) { |
| 51 | // The ServerSession received a sync request, this means that there's new data available | 58 | // The ServerSession received a sync request, this means that there's new data available |
| 52 | // from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or | 59 | // from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or |
| 53 | // similar. | 60 | // similar. |
| @@ -60,11 +67,14 @@ ResultCode ServerSession::HandleSyncRequest() { | |||
| 60 | return result; | 67 | return result; |
| 61 | hle_handler->HandleSyncRequest(SharedPtr<ServerSession>(this)); | 68 | hle_handler->HandleSyncRequest(SharedPtr<ServerSession>(this)); |
| 62 | // TODO(Subv): Translate the response command buffer. | 69 | // TODO(Subv): Translate the response command buffer. |
| 70 | } else { | ||
| 71 | // Add the thread to the list of threads that have issued a sync request with this | ||
| 72 | // server. | ||
| 73 | pending_requesting_threads.push_back(std::move(thread)); | ||
| 63 | } | 74 | } |
| 64 | 75 | ||
| 65 | // If this ServerSession does not have an HLE implementation, just wake up the threads waiting | 76 | // If this ServerSession does not have an HLE implementation, just wake up the threads waiting |
| 66 | // on it. | 77 | // on it. |
| 67 | signaled = true; | ||
| 68 | WakeupAllWaitingThreads(); | 78 | WakeupAllWaitingThreads(); |
| 69 | return RESULT_SUCCESS; | 79 | return RESULT_SUCCESS; |
| 70 | } | 80 | } |
| @@ -90,4 +100,4 @@ ResultCode TranslateHLERequest(ServerSession* server_session) { | |||
| 90 | // TODO(Subv): Implement this function once multiple concurrent processes are supported. | 100 | // TODO(Subv): Implement this function once multiple concurrent processes are supported. |
| 91 | return RESULT_SUCCESS; | 101 | return RESULT_SUCCESS; |
| 92 | } | 102 | } |
| 93 | } | 103 | } // namespace Kernel |
diff --git a/src/core/hle/kernel/server_session.h b/src/core/hle/kernel/server_session.h index 5365605da..f4360ddf3 100644 --- a/src/core/hle/kernel/server_session.h +++ b/src/core/hle/kernel/server_session.h | |||
| @@ -67,20 +67,30 @@ public: | |||
| 67 | 67 | ||
| 68 | /** | 68 | /** |
| 69 | * Handle a sync request from the emulated application. | 69 | * Handle a sync request from the emulated application. |
| 70 | * @param thread Thread that initiated the request. | ||
| 70 | * @returns ResultCode from the operation. | 71 | * @returns ResultCode from the operation. |
| 71 | */ | 72 | */ |
| 72 | ResultCode HandleSyncRequest(); | 73 | ResultCode HandleSyncRequest(SharedPtr<Thread> thread); |
| 73 | 74 | ||
| 74 | bool ShouldWait(Thread* thread) const override; | 75 | bool ShouldWait(Thread* thread) const override; |
| 75 | 76 | ||
| 76 | void Acquire(Thread* thread) override; | 77 | void Acquire(Thread* thread) override; |
| 77 | 78 | ||
| 78 | std::string name; ///< The name of this session (optional) | 79 | std::string name; ///< The name of this session (optional) |
| 79 | bool signaled; ///< Whether there's new data available to this ServerSession | ||
| 80 | std::shared_ptr<Session> parent; ///< The parent session, which links to the client endpoint. | 80 | std::shared_ptr<Session> parent; ///< The parent session, which links to the client endpoint. |
| 81 | std::shared_ptr<SessionRequestHandler> | 81 | std::shared_ptr<SessionRequestHandler> |
| 82 | hle_handler; ///< This session's HLE request handler (optional) | 82 | hle_handler; ///< This session's HLE request handler (optional) |
| 83 | 83 | ||
| 84 | /// List of threads that are pending a response after a sync request. This list is processed in | ||
| 85 | /// a LIFO manner, thus, the last request will be dispatched first. | ||
| 86 | /// TODO(Subv): Verify if this is indeed processed in LIFO using a hardware test. | ||
| 87 | std::vector<SharedPtr<Thread>> pending_requesting_threads; | ||
| 88 | |||
| 89 | /// Thread whose request is currently being handled. A request is considered "handled" when a | ||
| 90 | /// response is sent via svcReplyAndReceive. | ||
| 91 | /// TODO(Subv): Find a better name for this. | ||
| 92 | SharedPtr<Thread> currently_handling; | ||
| 93 | |||
| 84 | private: | 94 | private: |
| 85 | ServerSession(); | 95 | ServerSession(); |
| 86 | ~ServerSession() override; | 96 | ~ServerSession() override; |