From 9a1572c6624d8fd46af60045c91b69492d348bdd Mon Sep 17 00:00:00 2001 From: amgross <33063505+amgross@users.noreply.github.com> Date: Thu, 26 Dec 2024 13:24:38 +0200 Subject: [PATCH] Free the arbitrated client token from client manager --- erpc_c/infra/erpc_arbitrated_client_manager.cpp | 6 ++++++ erpc_c/infra/erpc_transport_arbitrator.cpp | 9 ++++++--- erpc_c/infra/erpc_transport_arbitrator.hpp | 14 +++++++------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/erpc_c/infra/erpc_arbitrated_client_manager.cpp b/erpc_c/infra/erpc_arbitrated_client_manager.cpp index f46682a7..9ad1072c 100644 --- a/erpc_c/infra/erpc_arbitrated_client_manager.cpp +++ b/erpc_c/infra/erpc_arbitrated_client_manager.cpp @@ -87,6 +87,12 @@ void ArbitratedClientManager::performClientRequest(RequestContext &request) request.getCodec()->updateStatus(err); } + if (token != 0) + { + // Also if status bad, need to free the token. + m_arbitrator->removePendingClient(token); + } + #if ERPC_MESSAGE_LOGGING if (request.getCodec()->isStatusOk() == true) { diff --git a/erpc_c/infra/erpc_transport_arbitrator.cpp b/erpc_c/infra/erpc_transport_arbitrator.cpp index dce2f021..45368c8d 100644 --- a/erpc_c/infra/erpc_transport_arbitrator.cpp +++ b/erpc_c/infra/erpc_transport_arbitrator.cpp @@ -193,8 +193,6 @@ erpc_status_t TransportArbitrator::clientReceive(client_token_t token) // Wait on the semaphore until we're signaled. info->m_sem.get(Semaphore::kWaitForever); - removePendingClient(info); - return kErpcStatus_Success; } @@ -227,11 +225,16 @@ TransportArbitrator::PendingClientInfo *TransportArbitrator::addPendingClient(vo return info; } -void TransportArbitrator::removePendingClient(PendingClientInfo *info) +void TransportArbitrator::removePendingClient(client_token_t token) { + // Convert token to pointer to info struct. + PendingClientInfo *info = reinterpret_cast(token); Mutex::Guard lock(m_clientListMutex); PendingClientInfo *node; + erpc_assert((token != 0) && ("invalid client token" != NULL)); + erpc_assert((info->m_sem.getCount() == 0) && ("Semaphore should be clean" != NULL)); + // Clear fields. info->m_request = NULL; info->m_isValid = false; diff --git a/erpc_c/infra/erpc_transport_arbitrator.hpp b/erpc_c/infra/erpc_transport_arbitrator.hpp index 049c58af..6a55efb0 100644 --- a/erpc_c/infra/erpc_transport_arbitrator.hpp +++ b/erpc_c/infra/erpc_transport_arbitrator.hpp @@ -157,6 +157,13 @@ class TransportArbitrator : public Transport */ erpc_status_t clientReceive(client_token_t token); + /*! + * @brief This function free client token. + * + * @param[in] token the client token to remove. + */ + void removePendingClient(client_token_t token); + /*! * @brief Request info for a client trying to receive a response. */ @@ -200,13 +207,6 @@ class TransportArbitrator : public Transport */ PendingClientInfo *addPendingClient(void); - /*! - * @brief This function removes pending client. - * - * @param[in] info Pending client info to remove. - */ - void removePendingClient(PendingClientInfo *info); - /*! * @brief This function removes pending client list. *