]> git.saurik.com Git - apple/libpthread.git/blob - tests/pthread_threadid_np.c
libpthread-301.20.1.tar.gz
[apple/libpthread.git] / tests / pthread_threadid_np.c
1 #include <pthread.h>
2 #include <pthread/private.h>
3 #include <dispatch/dispatch.h>
4
5 #include "darwintest_defaults.h"
6
7 extern __uint64_t __thread_selfid( void );
8
9 static void *do_test(void * __unused arg)
10 {
11 uint64_t threadid = __thread_selfid();
12 T_ASSERT_NOTNULL(threadid, NULL);
13
14 uint64_t pth_threadid = 0;
15 T_ASSERT_POSIX_ZERO(pthread_threadid_np(NULL, &pth_threadid), NULL);
16 T_ASSERT_POSIX_ZERO(pthread_threadid_np(pthread_self(), &pth_threadid), NULL);
17 T_EXPECT_EQ(threadid, pth_threadid, "pthread_threadid_np()");
18
19 pth_threadid = _pthread_threadid_self_np_direct();
20 T_EXPECT_EQ(threadid, pth_threadid, "pthread_threadid_np_direct()");
21
22 return NULL;
23 }
24
25 T_DECL(pthread_threadid_np, "pthread_threadid_np",
26 T_META_ALL_VALID_ARCHS(YES))
27 {
28 T_LOG("Main Thread");
29 do_test(NULL);
30
31 T_LOG("Pthread");
32 pthread_t pth;
33 T_ASSERT_POSIX_ZERO(pthread_create(&pth, NULL, do_test, NULL), NULL);
34 T_ASSERT_POSIX_ZERO(pthread_join(pth, NULL), NULL);
35
36 T_LOG("Workqueue Thread");
37 dispatch_queue_t dq = dispatch_queue_create("myqueue", NULL);
38 dispatch_async(dq, ^{ do_test(NULL); });
39 dispatch_sync(dq, ^{});
40
41 T_LOG("Workqueue Thread Reuse");
42 dispatch_async(dq, ^{ do_test(NULL); });
43 dispatch_sync(dq, ^{});
44 }