10 #include <sys/sysctl.h>
14 #include <pthread/tsd_private.h>
15 #include <pthread/qos_private.h>
16 #include <pthread/workqueue_private.h>
18 #include <dispatch/dispatch.h>
20 #include "darwintest_defaults.h"
22 T_DECL(bsdthread_set_self_constrained_transition
, "bsdthread_ctl(SET_SELF) with overcommit change",
23 T_META_ALL_VALID_ARCHS(YES
))
25 dispatch_async(dispatch_get_global_queue(0, 0), ^{
26 pthread_priority_t overcommit
= (pthread_priority_t
)_pthread_getspecific_direct(_PTHREAD_TSD_SLOT_PTHREAD_QOS_CLASS
) |
27 _PTHREAD_PRIORITY_OVERCOMMIT_FLAG
;
28 pthread_priority_t constrained
= overcommit
& (~_PTHREAD_PRIORITY_OVERCOMMIT_FLAG
);
30 T_ASSERT_POSIX_ZERO(_pthread_set_properties_self(_PTHREAD_SET_SELF_QOS_FLAG
, overcommit
, 0), NULL
);
31 T_ASSERT_POSIX_ZERO(_pthread_set_properties_self(_PTHREAD_SET_SELF_QOS_FLAG
, constrained
, 0), NULL
);
32 T_ASSERT_POSIX_ZERO(_pthread_set_properties_self(_PTHREAD_SET_SELF_QOS_FLAG
, overcommit
, 0), NULL
);
33 T_ASSERT_POSIX_ZERO(_pthread_set_properties_self(_PTHREAD_SET_SELF_QOS_FLAG
, constrained
, 0), NULL
);
34 T_ASSERT_POSIX_ZERO(_pthread_set_properties_self(_PTHREAD_SET_SELF_QOS_FLAG
, overcommit
, 0), NULL
);
35 T_ASSERT_POSIX_ZERO(_pthread_set_properties_self(_PTHREAD_SET_SELF_QOS_FLAG
, constrained
, 0), NULL
);
43 T_DECL(bsdthread_set_self_constrained_threads
, "bsdthread_ctl(SET_SELF) with overcommit change",
44 T_META_CHECK_LEAKS(NO
), T_META_ALL_VALID_ARCHS(YES
))
46 static const int THREADS
= 128;
47 static atomic_int threads_started
;
48 dispatch_queue_t q
= dispatch_queue_create("my queue", DISPATCH_QUEUE_CONCURRENT
);
49 dispatch_set_target_queue(q
, dispatch_get_global_queue(0, 0));
50 for (int i
= 0; i
< THREADS
; i
++) {
52 int thread_id
= ++threads_started
;
53 T_PASS("Thread %d started successfully", thread_id
);
54 if (thread_id
== THREADS
){
55 T_PASS("All threads started successfully");
59 pthread_priority_t overcommit
= (pthread_priority_t
)_pthread_getspecific_direct(_PTHREAD_TSD_SLOT_PTHREAD_QOS_CLASS
) |
60 _PTHREAD_PRIORITY_OVERCOMMIT_FLAG
;
61 T_ASSERT_POSIX_ZERO(_pthread_set_properties_self(_PTHREAD_SET_SELF_QOS_FLAG
, overcommit
, 0), NULL
);
63 uint64_t t
= clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW
);
64 while (t
> clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW
) - (thread_id
== 1 ? 30 : 60) * NSEC_PER_SEC
) {
68 T_FAIL("Where are my threads?");