[PATCH] perf ui/tui: Fix possible UI rendering breakage

From: Namhyung Kim
Date: Mon Nov 19 2018 - 20:56:03 EST


The tui_helpline__push() should acquire/release the ui__lock when it
deals with screen setting. Otherwise it could race with display thread
and screen rendering would not be handled properly.

Fixes: e6e904687949 ("perf ui: Introduce struct ui_helpline")
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/ui/tui/helpline.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tools/perf/ui/tui/helpline.c b/tools/perf/ui/tui/helpline.c
index 4ca799aadb4e..ff38b997f457 100644
--- a/tools/perf/ui/tui/helpline.c
+++ b/tools/perf/ui/tui/helpline.c
@@ -20,11 +20,13 @@ static void tui_helpline__push(const char *msg)
{
const size_t sz = sizeof(ui_helpline__current);

+ pthread_mutex_lock(&ui__lock);
SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
SLsmg_set_color(0);
SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols);
SLsmg_refresh();
strncpy(ui_helpline__current, msg, sz)[sz - 1] = '\0';
+ pthread_mutex_unlock(&ui__lock);
}

static int tui_helpline__show(const char *format, va_list ap)
--
2.19.0