Add locking and unlocking mutex 76/302376/1
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 6 Dec 2023 04:40:42 +0000 (13:40 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 6 Dec 2023 04:40:42 +0000 (13:40 +0900)
It is problematic if a callback invoke event is delivered to the main thread
while calling callback dispose() in the sub-thread.
To fix the thread safe issue, this patch adds locking & unlocking mutex.

Change-Id: I774a1598f9e64754cf27f22ca1c96f45f6995c16
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
idlc/gen/c_proxy_body_gen_cb.h

index 0757b2d975f34607c8b4b7da14c06db038ac3667..dc3e7814b03429bd0d2389f0e7eca64ce9cf33c1 100644 (file)
@@ -148,6 +148,7 @@ int rpc_port_proxy_##_dispose(rpc_port_proxy_$$_h proxy, rpc_port_##_h delegate)
         return -1;
     }
 
+    g_rec_mutex_lock(&proxy->mutex);
     iter = proxy->delegates;
     while (iter) {
         handle = (struct ##_s *)iter->data;
@@ -156,10 +157,12 @@ int rpc_port_proxy_##_dispose(rpc_port_proxy_$$_h proxy, rpc_port_##_h delegate)
             proxy->delegates = g_list_remove_link(proxy->delegates, iter);
             free(handle);
             g_list_free(iter);
+            g_rec_mutex_unlock(&proxy->mutex);
             return 0;
         }
         iter = g_list_next(iter);
     }
+    g_rec_mutex_unlock(&proxy->mutex);
 
     return -1;
 }
@@ -322,7 +325,9 @@ static void __##_on_received(const char *endpoint, const char *port_name, void *
         return;
     }
 
+    g_rec_mutex_lock(&handle->mutex);
     __##_process_received_event(&handle->delegates, parcel_received);
+    g_rec_mutex_unlock(&handle->mutex);
     rpc_port_parcel_destroy(parcel_received);
     _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name);
 }