From 2bfc129acb23a7e306bba65d2bdc107787690f19 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Sun, 28 Apr 2024 11:57:23 +0200 Subject: [PATCH 1/2] dbg: mutex should be unlocked while calling print handler --- src/dbg/dbg.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/dbg/dbg.c b/src/dbg/dbg.c index df3e74847..868372800 100644 --- a/src/dbg/dbg.c +++ b/src/dbg/dbg.c @@ -151,27 +151,24 @@ static void dbg_vprintf(int level, const char *fmt, va_list ap) static void dbg_fmt_vprintf(int level, const char *fmt, va_list ap) { char buf[256]; - int len; dbg_lock(); + int dbg_level = dbg.level; + dbg_print_h *ph = dbg.ph; + void *arg = dbg.arg; + dbg_unlock(); - if (level > dbg.level) - goto out; - - if (!dbg.ph) - goto out; - - len = re_vsnprintf(buf, sizeof(buf), fmt, ap); - if (len <= 0) - goto out; + if (level > dbg_level) + return; /* Print handler? */ - if (dbg.ph) { - dbg.ph(level, buf, len, dbg.arg); - } + if (ph) { + int len = re_vsnprintf(buf, sizeof(buf), fmt, ap); + if (len <= 0) + return; - out: - dbg_unlock(); + ph(level, buf, len, arg); + } } From 31692d105e2392d2453e87a8cddde10112173f5e Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:15:57 +0200 Subject: [PATCH 2/2] dbg_handler_set: add mutex --- src/dbg/dbg.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dbg/dbg.c b/src/dbg/dbg.c index 868372800..0e84cf3d2 100644 --- a/src/dbg/dbg.c +++ b/src/dbg/dbg.c @@ -91,8 +91,10 @@ void dbg_close(void) */ void dbg_handler_set(dbg_print_h *ph, void *arg) { + dbg_lock(); dbg.ph = ph; dbg.arg = arg; + dbg_unlock(); }