From 0e947166aa8e9e09e5d61a0eef2857fd522e8924 Mon Sep 17 00:00:00 2001 From: Daniel Zaoui Date: Fri, 9 Jun 2017 01:09:38 +0300 Subject: [PATCH] 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. --- src/lib/eina/eina_debug.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib/eina/eina_debug.c b/src/lib/eina/eina_debug.c index 80f5e1d245..4175b87155 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);