agm: add mutex lock for agm_session_register_cb()
The current implementation allows different
processes to enter the function and manipulate
with the data inside; race condition can occur.
Adding mutex lock to regard from the beginning to
the returns as critical section so as to resolve
race condition.
Change-Id: Idef15bb2620a8e3516f574594641038e60d8429b
diff --git a/ipc/HwBinders/agm_ipc_client/src/agm_client_wrapper.cpp b/ipc/HwBinders/agm_ipc_client/src/agm_client_wrapper.cpp
index de56c56..520a2af 100644
--- a/ipc/HwBinders/agm_ipc_client/src/agm_client_wrapper.cpp
+++ b/ipc/HwBinders/agm_ipc_client/src/agm_client_wrapper.cpp
@@ -71,6 +71,7 @@
#include <agm/agm_api.h>
#include "inc/AGMCallback.h"
+#include <mutex>
using android::hardware::Return;
using android::hardware::hidl_vec;
@@ -91,6 +92,7 @@
sp<IAGMCallback> ClbkBinder = NULL;
static list_declare(client_clbk_data_list);
static pthread_mutex_t clbk_data_list_lock = PTHREAD_MUTEX_INITIALIZER;
+static std::mutex agm_session_register_cb_mutex;
struct client_cb_data {
struct listnode node;
@@ -730,6 +732,7 @@
int agm_session_register_cb(uint32_t session_id, agm_event_cb cb,
enum event_type evt_type, void *client_data)
{
+ std::lock_guard<std::mutex> lck(agm_session_register_cb_mutex);
ALOGV("%s : sess_id = %d, evt_type = %d, client_data = %p \n", __func__,
session_id, evt_type, client_data);
int32_t ret = 0;