From: Daniel Zaoui Date: Thu, 8 Jun 2017 22:09:38 +0000 (+0300) Subject: Eina Debug: fix a bug resulting in registering opcodes twice X-Git-Tag: upstream/1.20.0~642 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0e947166aa8e9e09e5d61a0eef2857fd522e8924;p=platform%2Fupstream%2Fefl.git Eina Debug: fix a bug resulting in registering opcodes twice The opcodes registration request is sent directly in case the connection is already made. Otherwise, the request is waiting for the connection to be made by the dedicated thread (not the main loop). That's why the request can be sent by the two different threads at the same time, leading to send it twice. It means a callback for an opcode would be invoked twice everytime a request with this opcode is received. This patch fixes it by checking if the request has already been sent. --- diff --git a/src/lib/eina/eina_debug.c b/src/lib/eina/eina_debug.c index 80f5e1d..4175b87 100644 --- a/src/lib/eina/eina_debug.c +++ b/src/lib/eina/eina_debug.c @@ -120,6 +120,7 @@ typedef struct const Eina_Debug_Opcode *ops; Eina_Debug_Opcode_Status_Cb status_cb; void *status_data; + Eina_Bool sent : 1; } _opcode_reply_info; struct _Eina_Debug_Session @@ -345,6 +346,13 @@ _opcodes_registration_send(Eina_Debug_Session *session, int count = 0; int size = sizeof(uint64_t); + Eina_Bool already_sent; + + eina_spinlock_take(&_eina_debug_lock); + already_sent = info->sent; + info->sent = EINA_TRUE; + eina_spinlock_release(&_eina_debug_lock); + if (already_sent) return; while (info->ops[count].opcode_name) { @@ -625,6 +633,7 @@ eina_debug_opcodes_register(Eina_Debug_Session *session, const Eina_Debug_Opcode info->ops = ops; info->status_cb = status_cb; info->status_data = data; + info->sent = EINA_FALSE; session->opcode_reply_infos = eina_list_append( session->opcode_reply_infos, info);