[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / lldb / packages / Python / lldbsuite / test / macosx / queues / main.c
blob3978b92bff1a62fd0792a65cd650c059e4e78745
1 #include <stdatomic.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <dispatch/dispatch.h>
5 #include <pthread.h>
7 atomic_int finished_enqueueing_work = 0;
8 atomic_int thread_count = 0;
10 void
11 doing_the_work_1(void *in)
13 // This is only counted once because the first job in the queue
14 // starves all the others.
15 atomic_fetch_add(&thread_count, 1);
16 while (1)
17 sleep (1);
20 void
21 submit_work_1a(void *in)
23 dispatch_queue_t *work_performer_1 = (dispatch_queue_t*) in;
24 dispatch_async_f (*work_performer_1, NULL, doing_the_work_1);
25 dispatch_async_f (*work_performer_1, NULL, doing_the_work_1);
28 void
29 submit_work_1b(void *in)
31 dispatch_queue_t *work_performer_1 = (dispatch_queue_t*) in;
32 dispatch_async_f (*work_performer_1, NULL, doing_the_work_1);
33 dispatch_async_f (*work_performer_1, NULL, doing_the_work_1);
34 atomic_fetch_add(&thread_count, 1);
35 while (1)
36 sleep (1);
39 void
40 doing_the_work_2(void *in)
42 atomic_fetch_add(&thread_count, 1);
43 while (1)
44 sleep (1);
47 void
48 submit_work_2(void *in)
50 dispatch_queue_t *work_performer_2 = (dispatch_queue_t*) in;
51 int i = 0;
52 while (i++ < 5000)
54 dispatch_async_f (*work_performer_2, NULL, doing_the_work_2);
55 dispatch_async_f (*work_performer_2, NULL, doing_the_work_2);
57 atomic_fetch_add(&finished_enqueueing_work, 1);
61 void
62 doing_the_work_3(void *in)
64 // This counts four times, since the queue is marked as CONCURRENT.
65 atomic_fetch_add(&thread_count, 1);
66 while (1)
67 sleep (1);
70 void
71 submit_work_3(void *in)
73 dispatch_queue_t *work_performer_3 = (dispatch_queue_t*) in;
74 dispatch_async_f (*work_performer_3, NULL, doing_the_work_3);
75 dispatch_async_f (*work_performer_3, NULL, doing_the_work_3);
76 dispatch_async_f (*work_performer_3, NULL, doing_the_work_3);
77 dispatch_async_f (*work_performer_3, NULL, doing_the_work_3);
81 void
82 stopper ()
84 while (1)
85 sleep (1);
89 int main (int argc, const char **argv)
91 dispatch_queue_t work_submittor_1 = dispatch_queue_create ("com.apple.work_submittor_1", DISPATCH_QUEUE_SERIAL);
92 dispatch_queue_t work_submittor_2 = dispatch_queue_create ("com.apple.work_submittor_and_quit_2", DISPATCH_QUEUE_SERIAL);
93 dispatch_queue_t work_submittor_3 = dispatch_queue_create ("com.apple.work_submittor_3", DISPATCH_QUEUE_SERIAL);
95 dispatch_queue_t work_performer_1 = dispatch_queue_create ("com.apple.work_performer_1", DISPATCH_QUEUE_SERIAL);
96 dispatch_queue_t work_performer_2 = dispatch_queue_create ("com.apple.work_performer_2", DISPATCH_QUEUE_SERIAL);
98 dispatch_queue_t work_performer_3 = dispatch_queue_create ("com.apple.work_performer_3", DISPATCH_QUEUE_CONCURRENT);
100 dispatch_async_f (work_submittor_1, (void*) &work_performer_1, submit_work_1a);
101 dispatch_async_f (work_submittor_1, (void*) &work_performer_1, submit_work_1b);
103 dispatch_async_f (work_submittor_2, (void*) &work_performer_2, submit_work_2);
105 dispatch_async_f (work_submittor_3, (void*) &work_performer_3, submit_work_3);
108 // Spin up threads with each of the different libdispatch QoS values.
109 dispatch_async (dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
110 pthread_setname_np ("user initiated QoS");
111 atomic_fetch_add(&thread_count, 1);
112 while (1)
113 sleep (10);
115 dispatch_async (dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
116 pthread_setname_np ("user interactive QoS");
117 atomic_fetch_add(&thread_count, 1);
118 while (1)
119 sleep (10);
121 dispatch_async (dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
122 pthread_setname_np ("default QoS");
123 atomic_fetch_add(&thread_count, 1);
124 while (1)
125 sleep (10);
127 dispatch_async (dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{
128 pthread_setname_np ("utility QoS");
129 atomic_fetch_add(&thread_count, 1);
130 while (1)
131 sleep (10);
133 dispatch_async (dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
134 pthread_setname_np ("background QoS");
135 atomic_fetch_add(&thread_count, 1);
136 while (1)
137 sleep (10);
139 dispatch_async (dispatch_get_global_queue(QOS_CLASS_UNSPECIFIED, 0), ^{
140 pthread_setname_np ("unspecified QoS");
141 atomic_fetch_add(&thread_count, 1);
142 while (1)
143 sleep (10);
146 // Unfortunately there is no pthread_barrier on darwin.
147 while ((atomic_load(&thread_count) < 13) || (finished_enqueueing_work == 0))
148 sleep (1);
150 stopper ();