Skip to content

Commit

Permalink
dbg: mutex should be unlocked while calling print handler (#1113)
Browse files Browse the repository at this point in the history
* dbg: mutex should be unlocked while calling print handler

* dbg_handler_set: add mutex
  • Loading branch information
alfredh authored Apr 30, 2024
1 parent 1b54c8a commit 411208e
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/dbg/dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


Expand Down Expand Up @@ -151,27 +153,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);
}
}


Expand Down

0 comments on commit 411208e

Please sign in to comment.