From: Hwankyu Jhun Date: Tue, 17 Apr 2018 02:43:18 +0000 (+0900) Subject: Make thread safe code X-Git-Tag: submit/tizen/20180417.094831~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6cbefb82d8aa6988ba8058e6b7b583a40bb30b18;p=platform%2Fcore%2Fappfw%2Ftidl.git Make thread safe code - Adds locking and unlocking the mutex on generated C codes Change-Id: Ibdaa68cdd1ef3591160e0cb06e753043270986e0 Signed-off-by: Hwankyu Jhun --- diff --git a/idlc/c_gen/c_proxy_body_gen_cb.h b/idlc/c_gen/c_proxy_body_gen_cb.h index cbaba8b4..2474451d 100644 --- a/idlc/c_gen/c_proxy_body_gen_cb.h +++ b/idlc/c_gen/c_proxy_body_gen_cb.h @@ -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";