Skip to content

Commit 5fdae9d

Browse files
jeffhostetlergitster
authored andcommitted
trace2: fix tracing when NO_PTHREADS is defined
Teach trace2 TLS code to not rely on pthread_getspecific() when NO_PTHREADS is defined. Instead, always assume the context data of the main thread. Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c173542 commit 5fdae9d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

trace2/tr2_tls.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)
4747

4848
struct tr2tls_thread_ctx *tr2tls_get_self(void)
4949
{
50-
struct tr2tls_thread_ctx *ctx = pthread_getspecific(tr2tls_key);
50+
struct tr2tls_thread_ctx *ctx;
51+
52+
if (!HAVE_THREADS)
53+
return tr2tls_thread_main;
54+
55+
ctx = pthread_getspecific(tr2tls_key);
5156

5257
/*
5358
* If the thread-proc did not call trace2_thread_start(), we won't
@@ -62,9 +67,10 @@ struct tr2tls_thread_ctx *tr2tls_get_self(void)
6267

6368
int tr2tls_is_main_thread(void)
6469
{
65-
struct tr2tls_thread_ctx *ctx = pthread_getspecific(tr2tls_key);
70+
if (!HAVE_THREADS)
71+
return 1;
6672

67-
return ctx == tr2tls_thread_main;
73+
return pthread_getspecific(tr2tls_key) == tr2tls_thread_main;
6874
}
6975

7076
void tr2tls_unset_self(void)

0 commit comments

Comments
 (0)