From 860394244b13260f70417c673b3eaae545113af7 Mon Sep 17 00:00:00 2001 From: Cedric Roux <cedric.roux@eurecom.fr> Date: Mon, 28 Nov 2016 18:28:10 +0100 Subject: [PATCH] T: bugfix: lock required When the user clicks on "next UE" or "prev UE" we change the filters of loggers. At the same time, the main thread of enb.c processes events received from the soft-modem and uses the filters, some of them maybe in the process of being changed. Changing the filters is not atomic and has to be protected. --- common/utils/T/tracer/enb.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/common/utils/T/tracer/enb.c b/common/utils/T/tracer/enb.c index 5d785782ea..07768763a5 100644 --- a/common/utils/T/tracer/enb.c +++ b/common/utils/T/tracer/enb.c @@ -190,8 +190,12 @@ static void click(void *private, gui *g, if (w == e->prev_ue_button) { ue--; if (ue < 0) ue = 0; } if (w == e->next_ue_button) ue++; - if (ue != ed->ue) set_current_ue(g, ed, ue); - ed->ue = ue; + if (pthread_mutex_lock(&ed->lock)) abort(); + if (ue != ed->ue) { + set_current_ue(g, ed, ue); + ed->ue = ue; + } + if (pthread_mutex_unlock(&ed->lock)) abort(); } static void enb_main_gui(enb_gui *e, gui *g, event_handler *h, void *database, @@ -745,7 +749,9 @@ restart: event e; e = get_event(enb_data.socket, v, database); if (e.type == -1) goto restart; + if (pthread_mutex_lock(&enb_data.lock)) abort(); handle_event(h, e); + if (pthread_mutex_unlock(&enb_data.lock)) abort(); } return 0; -- GitLab