Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main: add debug boolean to re_thread_check() #775

Merged
merged 2 commits into from
Apr 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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