Skip to content

Commit

Permalink
main: add debug boolean to re_thread_check() (baresip#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers authored and Vladimir Orlov committed May 11, 2023
1 parent f0fd286 commit 5f2df2b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/re_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int re_thread_init(void);
void re_thread_close(void);
void re_thread_enter(void);
void re_thread_leave(void);
int re_thread_check(void);
int re_thread_check(bool debug);
int re_thread_async_init(uint16_t workers);
void re_thread_async_close(void);
int re_thread_async(re_async_work_h *work, re_async_h *cb, void *arg);
Expand Down
17 changes: 10 additions & 7 deletions src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ int fd_listen(re_sock_t fd, int flags, fd_h *fh, void *arg)
DEBUG_INFO("fd_listen: fd=%d flags=0x%02x\n", fd, flags);

#ifndef RELEASE
err = re_thread_check();
err = re_thread_check(true);
if (err)
return err;
#endif
Expand Down Expand Up @@ -1306,7 +1306,7 @@ void re_set_mutex(void *mutexp)
*
* @return 0 if success, otherwise EPERM
*/
int re_thread_check(void)
int re_thread_check(bool debug)
{
struct re *re = re_get();

Expand All @@ -1319,14 +1319,17 @@ int re_thread_check(void)
if (thrd_equal(re->tid, thrd_current()))
return 0;

DEBUG_WARNING("thread check: called from a NON-RE thread without "
"thread_enter()!\n");
if (debug) {
DEBUG_WARNING(
"thread check: called from a NON-RE thread without "
"thread_enter()!\n");

#if DEBUG_LEVEL > 5
struct btrace trace;
btrace(&trace);
DEBUG_INFO("%H", btrace_println, &trace);
struct btrace trace;
btrace(&trace);
DEBUG_INFO("%H", btrace_println, &trace);
#endif
}

return EPERM;
}
Expand Down
2 changes: 1 addition & 1 deletion test/async.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static void completed(int err, void *arg)
if (err)
goto out;

err = re_thread_check();
err = re_thread_check(false);
TEST_ERR(err);

sa_set_str(&sa, "127.0.0.1", 0);
Expand Down

0 comments on commit 5f2df2b

Please sign in to comment.