Skip to content

trace2: fix tracing when NO_PTHREADS is defined #222

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

Closed
Closed
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
12 changes: 9 additions & 3 deletions trace2/tr2_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,

struct tr2tls_thread_ctx *tr2tls_get_self(void)
{
struct tr2tls_thread_ctx *ctx = pthread_getspecific(tr2tls_key);
struct tr2tls_thread_ctx *ctx;

if (!HAVE_THREADS)
return tr2tls_thread_main;

ctx = pthread_getspecific(tr2tls_key);

/*
* If the thread-proc did not call trace2_thread_start(), we won't
Expand All @@ -76,9 +81,10 @@ struct tr2tls_thread_ctx *tr2tls_get_self(void)

int tr2tls_is_main_thread(void)
{
struct tr2tls_thread_ctx *ctx = pthread_getspecific(tr2tls_key);
if (!HAVE_THREADS)
return 1;

return ctx == tr2tls_thread_main;
return pthread_getspecific(tr2tls_key) == tr2tls_thread_main;
}

void tr2tls_unset_self(void)
Expand Down