test-lib: introduce test_commit_bulk
[gitweb.git] / trace2 / tr2_tls.c
index e76d8c5d92aec764280506bb78cd7e4a3e48eeb2..067c23755fb557895bf8cd12d497130dd55041fe 100644 (file)
@@ -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
@@ -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)