From 6ffa65f1d215a528f35821f7883d147dece7fc65 Mon Sep 17 00:00:00 2001 From: Cedric Roux <cedric.roux@eurecom.fr> Date: Sun, 1 May 2016 14:06:20 +0200 Subject: [PATCH] get rid of X locks, there were missing glock/gunlock here and there --- common/utils/T/tracer/gui/gui.c | 12 +++++++++--- common/utils/T/tracer/gui/init.c | 7 +++++-- common/utils/T/tracer/gui/loop.c | 7 +++++++ common/utils/T/tracer/gui/x.c | 17 ----------------- common/utils/T/tracer/gui/x.h | 5 ----- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/common/utils/T/tracer/gui/gui.c b/common/utils/T/tracer/gui/gui.c index 2166774d9..ef8640b0d 100644 --- a/common/utils/T/tracer/gui/gui.c +++ b/common/utils/T/tracer/gui/gui.c @@ -9,18 +9,24 @@ void glock(gui *_gui) { struct gui *g = _gui; if (pthread_mutex_lock(g->lock)) ERR("mutex error\n"); - xlock(g->x); } void gunlock(gui *_gui) { struct gui *g = _gui; - xunlock(g->x); if (pthread_mutex_unlock(g->lock)) ERR("mutex error\n"); } int new_color(gui *_gui, char *color) { struct gui *g = _gui; - return x_new_color(g->x, color); + int ret; + + glock(g); + + ret = x_new_color(g->x, color); + + gunlock(g); + + return ret; } diff --git a/common/utils/T/tracer/gui/init.c b/common/utils/T/tracer/gui/init.c index 445f69664..c6d5e3e43 100644 --- a/common/utils/T/tracer/gui/init.c +++ b/common/utils/T/tracer/gui/init.c @@ -12,8 +12,6 @@ gui *gui_init(void) { struct gui *ret; - x_init_threading(); - ret = calloc(1, sizeof(struct gui)); if (ret == NULL) OOM; @@ -25,7 +23,12 @@ gui *gui_init(void) if (pipe(ret->event_pipe)) ERR("%s\n", strerror(errno)); + /* lock not necessary but there for consistency (when instrumenting x.c + * we need the gui to be locked when calling any function in x.c) + */ + glock(ret); ret->x = x_open(); + gunlock(ret); return ret; } diff --git a/common/utils/T/tracer/gui/loop.c b/common/utils/T/tracer/gui/loop.c index 94b7fe54b..8ceb3c06e 100644 --- a/common/utils/T/tracer/gui/loop.c +++ b/common/utils/T/tracer/gui/loop.c @@ -16,14 +16,21 @@ void gui_loop(gui *_gui) int maxfd; fd_set rd; + /* lock not necessary but there for consistency (when instrumenting x.c + * we need the gui to be locked when calling any function in x.c) + */ + glock(g); xfd = x_connection_fd(g->x); + gunlock(g); eventfd = g->event_pipe[0]; if (eventfd > xfd) maxfd = eventfd; else maxfd = xfd; while (1) { + glock(g); x_flush(g->x); + gunlock(g); FD_ZERO(&rd); FD_SET(xfd, &rd); FD_SET(eventfd, &rd); diff --git a/common/utils/T/tracer/gui/x.c b/common/utils/T/tracer/gui/x.c index 12888da46..50164dce3 100644 --- a/common/utils/T/tracer/gui/x.c +++ b/common/utils/T/tracer/gui/x.c @@ -6,23 +6,6 @@ #include <stdlib.h> #include <string.h> -void x_init_threading(void) -{ - if (XInitThreads() == False) abort(); -} - -void xlock(x_connection *_x) -{ - struct x_connection *x = _x; - XLockDisplay(x->d); -} - -void xunlock(x_connection *_x) -{ - struct x_connection *x = _x; - XUnlockDisplay(x->d); -} - int x_connection_fd(x_connection *_x) { struct x_connection *x = _x; diff --git a/common/utils/T/tracer/gui/x.h b/common/utils/T/tracer/gui/x.h index 82e46cac9..c1f8d33d8 100644 --- a/common/utils/T/tracer/gui/x.h +++ b/common/utils/T/tracer/gui/x.h @@ -6,11 +6,6 @@ typedef void x_connection; typedef void x_window; -void x_init_threading(void); - -void xlock(x_connection *x); -void xunlock(x_connection *x); - x_connection *x_open(void); x_window *x_create_window(x_connection *x, int width, int height, -- GitLab