]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
test_threads_create: add a macOS fallback
authorThomas Weißschuh <thomas@t-8ch.de>
Wed, 13 May 2026 13:56:09 +0000 (15:56 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Thu, 14 May 2026 11:19:43 +0000 (13:19 +0200)
SYS_gettid is Linux-specific. Add a fallback for macOS.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
tests/helpers/test_threads_create.c

index d50d74f83092cc73f18668ee01a9b3f32c2dd940..50ff53b93ede31ec17bbe751a4be5aa2dea01577 100644 (file)
@@ -49,12 +49,20 @@ struct thread_ctl {
 
 static void* thread_func(void* arg)
 {
-       pid_t tid = syscall(SYS_gettid);
+       uint64_t tid;
+
+#if defined(__linux__)
+       tid = syscall(SYS_gettid);
+#elif defined(__APPLE__)
+       pthread_threadid_np(NULL, &tid);
+#else
+#error Unsupported operating system
+#endif
        struct thread_ctl *tctl = (struct thread_ctl *)arg;
        int id = tctl->thread_id + 2;
        uint16_t sec = tctl->sleep_time;
 
-       printf("Thread %d: %d\n", id, tid);
+       printf("Thread %d: %"PRIu64"\n", id, tid);
        sleep(sec);
 
        free(arg);