Make thread safe code 34/176134/6
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 17 Apr 2018 02:43:18 +0000 (11:43 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Tue, 17 Apr 2018 09:36:08 +0000 (09:36 +0000)
- Adds locking and unlocking the mutex on generated C codes

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

index cbaba8b..2474451 100644 (file)
@@ -23,6 +23,7 @@ struct ##_s {
     rpc_port_proxy_##_callback_s callback;
     void *user_data;
     GList *delegates;
+    GRecMutex mutex;
 };
 )__c_cb";
 
@@ -249,17 +250,20 @@ static void __##_on_received(const char *endpoint, const char *port_name, void *
     rpc_port_parcel_h parcel_received;
     int cmd = -1;
 
+    g_rec_mutex_lock(&handle->mutex);
     rpc_port_parcel_create_from_port(&parcel_received, handle->port);
     rpc_port_parcel_read_int32(parcel_received, &cmd);
     if (cmd != ##_METHOD_Callback) {
         dlog_print(DLOG_ERROR, LOG_TAG, "Invalid protocol");
         rpc_port_parcel_destroy(parcel_received);
+        g_rec_mutex_unlock(&handle->mutex);
         return;
     }
 
     __##_process_received_event(&handle->delegates, parcel_received);
     rpc_port_parcel_destroy(parcel_received);
     dlog_print(DLOG_INFO, LOG_TAG, "[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name);
+    g_rec_mutex_unlock(&handle->mutex);
 }
 )__c_cb";
 
@@ -316,6 +320,8 @@ static struct ##_s *__create_##(const char *stub_appid, rpc_port_proxy_##_callba
         return NULL;
     }
 
+    g_rec_mutex_init(&handle->mutex);
+
     handle->callback = *callback;
     handle->user_data = user_data;
 
@@ -330,12 +336,17 @@ static void __destroy_##(struct ##_s *h)
     if (!h)
         return;
 
+    g_rec_mutex_clear(&h->mutex);
+
     if (h->delegates)
         g_list_free_full(h->delegates, free);
+
     if (h->proxy)
         rpc_port_proxy_destroy(h->proxy);
+
     if (h->stub_appid)
         free(h->stub_appid);
+
     free(h);
 }
 )__c_cb";
@@ -423,6 +434,7 @@ do {
 
 const char CB_RECEIVE_BLOCK[] =
 R"__c_cb(
+g_rec_mutex_lock(&h->mutex);
 do {
     rpc_port_parcel_h parcel_received;
 $$
@@ -435,4 +447,5 @@ $$
 $$
     rpc_port_parcel_destroy(parcel_received);
 } while (0);
+g_rec_mutex_unlock(&h->mutex);
 )__c_cb";