Skip to content

Commit

Permalink
Use mutex to protect the sessions context list
Browse files Browse the repository at this point in the history
Signed-off-by: Kasiewicz, Marek <marek.kasiewicz@intel.com>
  • Loading branch information
Sakoram committed Nov 19, 2024
1 parent 9a5c536 commit d3824ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions media-proxy/include/proxy_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "session-mtl.h"
#include "session-rdma.h"
#include <mutex>

#pragma once

Expand All @@ -34,6 +35,7 @@ class ProxyContext {
std::vector<Session *> mDpCtx;
mtl_handle mDevHandle = NULL;
libfabric_ctx *mDevHandle_rdma = NULL;
std::mutex ctx_mtx;

bool imtl_init_preparing;
pthread_mutex_t mutex_lock;
Expand Down
5 changes: 4 additions & 1 deletion media-proxy/src/api_server_tcp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ void* msg_loop(void* ptr)
/* TODO: return memdif ID */
break;
case MCM_QUERY_MEMIF_PARAM:
{
DEBUG("MCM_QUERY_MEMIF_PARAM: Case entry.");
if (buffer == NULL || msg.command.data_len < 4) {
INFO("Invalid parameters.");
break;
}
std::lock_guard<std::mutex> lock(proxy_ctx->ctx_mtx);
session_id = *(uint32_t*)buffer;
for (auto it : proxy_ctx->mDpCtx) {
if (it->get_id() == session_id) {
Expand All @@ -152,7 +154,8 @@ void* msg_loop(void* ptr)
break;
}
}
break;
break;
}
case MCM_DESTROY_SESSION:
DEBUG("MCM_DESTROY_SESSION: Case entry.");
if (buffer == NULL || msg.command.data_len < 4) {
Expand Down
5 changes: 5 additions & 0 deletions media-proxy/src/proxy_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ int ProxyContext::RxStart_rdma(const mcm_conn_param *request)
}

INFO("%s, session id: %d", __func__, session_ptr->get_id());
std::lock_guard<std::mutex> lock(ctx_mtx);
mDpCtx.push_back(session_ptr);
return session_ptr->get_id();
}
Expand Down Expand Up @@ -251,6 +252,7 @@ int ProxyContext::RxStart_mtl(const mcm_conn_param *request)
}

INFO("%s, session id: %d", __func__, session_ptr->get_id());
std::lock_guard<std::mutex> lock(ctx_mtx);
mDpCtx.push_back(session_ptr);
return session_ptr->get_id();
}
Expand Down Expand Up @@ -287,6 +289,7 @@ int ProxyContext::TxStart_rdma(const mcm_conn_param *request)
}

INFO("%s, session id: %d", __func__, session_ptr->get_id());
std::lock_guard<std::mutex> lock(ctx_mtx);
mDpCtx.push_back(session_ptr);
return session_ptr->get_id();
}
Expand Down Expand Up @@ -351,6 +354,7 @@ int ProxyContext::TxStart_mtl(const mcm_conn_param *request)
}

INFO("%s, session id: %d", __func__, session_ptr->get_id());
std::lock_guard<std::mutex> lock(ctx_mtx);
mDpCtx.push_back(session_ptr);
return session_ptr->get_id();
}
Expand All @@ -366,6 +370,7 @@ int ProxyContext::TxStart(const mcm_conn_param *request)
int ProxyContext::Stop(const int32_t session_id)
{
int ret = 0;
std::lock_guard<std::mutex> lock(ctx_mtx);
auto ctx = std::find_if(mDpCtx.begin(), mDpCtx.end(),
[session_id](auto it) { return it->get_id() == session_id; });
if (ctx != mDpCtx.end()) {
Expand Down

0 comments on commit d3824ee

Please sign in to comment.