23
23
#include "protocol.h" // _dispatch_send_wakeup_runloop_thread
24
24
#endif
25
25
26
- #if (!HAVE_PTHREAD_WORKQUEUES || DISPATCH_DEBUG || DISPATCH_USE_INTERNAL_WORKQUEUE ) && \
27
- !defined(DISPATCH_ENABLE_THREAD_POOL )
26
+ #if HAVE_PTHREAD_WORKQUEUES || DISPATCH_USE_INTERNAL_WORKQUEUE
27
+ #define DISPATCH_USE_WORKQUEUES 1
28
+ #endif
29
+ #if (!HAVE_PTHREAD_WORKQUEUES || DISPATCH_DEBUG ) && !defined(DISPATCH_ENABLE_THREAD_POOL )
28
30
#define DISPATCH_ENABLE_THREAD_POOL 1
29
31
#endif
30
32
#if DISPATCH_ENABLE_PTHREAD_ROOT_QUEUES || DISPATCH_ENABLE_THREAD_POOL
31
33
#define DISPATCH_USE_PTHREAD_POOL 1
32
34
#endif
33
35
#if HAVE_PTHREAD_WORKQUEUES && (!HAVE_PTHREAD_WORKQUEUE_QOS || DISPATCH_DEBUG ) && \
34
36
!HAVE_PTHREAD_WORKQUEUE_SETDISPATCH_NP && \
35
- !DISPATCH_USE_INTERNAL_WORKQUEUE && \
36
37
!defined(DISPATCH_USE_LEGACY_WORKQUEUE_FALLBACK )
37
38
#define DISPATCH_USE_LEGACY_WORKQUEUE_FALLBACK 1
38
39
#endif
39
- #if HAVE_PTHREAD_WORKQUEUES && DISPATCH_USE_PTHREAD_POOL && \
40
+ #if DISPATCH_USE_WORKQUEUES && DISPATCH_USE_PTHREAD_POOL && \
40
41
!DISPATCH_USE_LEGACY_WORKQUEUE_FALLBACK
41
42
#define pthread_workqueue_t void*
42
43
#endif
@@ -155,13 +156,13 @@ struct dispatch_root_queue_context_s {
155
156
union {
156
157
struct {
157
158
int volatile dgq_pending ;
158
- #if HAVE_PTHREAD_WORKQUEUES
159
+ #if DISPATCH_USE_WORKQUEUES
159
160
qos_class_t dgq_qos ;
160
161
int dgq_wq_priority , dgq_wq_options ;
161
162
#if DISPATCH_USE_LEGACY_WORKQUEUE_FALLBACK || DISPATCH_USE_PTHREAD_POOL
162
163
pthread_workqueue_t dgq_kworkqueue ;
163
164
#endif
164
- #endif // HAVE_PTHREAD_WORKQUEUES
165
+ #endif // DISPATCH_USE_WORKQUEUES
165
166
#if DISPATCH_USE_PTHREAD_POOL
166
167
void * dgq_ctxt ;
167
168
int32_t volatile dgq_thread_pool_size ;
@@ -183,7 +184,7 @@ typedef struct dispatch_root_queue_context_s *dispatch_root_queue_context_t;
183
184
DISPATCH_CACHELINE_ALIGN
184
185
static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts [] = {
185
186
[DISPATCH_ROOT_QUEUE_IDX_MAINTENANCE_QOS ] = {{{
186
- #if HAVE_PTHREAD_WORKQUEUES
187
+ #if DISPATCH_USE_WORKQUEUES
187
188
.dgq_qos = QOS_CLASS_MAINTENANCE ,
188
189
.dgq_wq_priority = WORKQ_BG_PRIOQUEUE ,
189
190
.dgq_wq_options = 0 ,
@@ -194,7 +195,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
194
195
#endif
195
196
}}},
196
197
[DISPATCH_ROOT_QUEUE_IDX_MAINTENANCE_QOS_OVERCOMMIT ] = {{{
197
- #if HAVE_PTHREAD_WORKQUEUES
198
+ #if DISPATCH_USE_WORKQUEUES
198
199
.dgq_qos = QOS_CLASS_MAINTENANCE ,
199
200
.dgq_wq_priority = WORKQ_BG_PRIOQUEUE ,
200
201
.dgq_wq_options = WORKQ_ADDTHREADS_OPTION_OVERCOMMIT ,
@@ -205,7 +206,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
205
206
#endif
206
207
}}},
207
208
[DISPATCH_ROOT_QUEUE_IDX_BACKGROUND_QOS ] = {{{
208
- #if HAVE_PTHREAD_WORKQUEUES
209
+ #if DISPATCH_USE_WORKQUEUES
209
210
.dgq_qos = QOS_CLASS_BACKGROUND ,
210
211
.dgq_wq_priority = WORKQ_BG_PRIOQUEUE_CONDITIONAL ,
211
212
.dgq_wq_options = 0 ,
@@ -216,7 +217,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
216
217
#endif
217
218
}}},
218
219
[DISPATCH_ROOT_QUEUE_IDX_BACKGROUND_QOS_OVERCOMMIT ] = {{{
219
- #if HAVE_PTHREAD_WORKQUEUES
220
+ #if DISPATCH_USE_WORKQUEUES
220
221
.dgq_qos = QOS_CLASS_BACKGROUND ,
221
222
.dgq_wq_priority = WORKQ_BG_PRIOQUEUE_CONDITIONAL ,
222
223
.dgq_wq_options = WORKQ_ADDTHREADS_OPTION_OVERCOMMIT ,
@@ -227,7 +228,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
227
228
#endif
228
229
}}},
229
230
[DISPATCH_ROOT_QUEUE_IDX_UTILITY_QOS ] = {{{
230
- #if HAVE_PTHREAD_WORKQUEUES
231
+ #if DISPATCH_USE_WORKQUEUES
231
232
.dgq_qos = QOS_CLASS_UTILITY ,
232
233
.dgq_wq_priority = WORKQ_LOW_PRIOQUEUE ,
233
234
.dgq_wq_options = 0 ,
@@ -238,7 +239,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
238
239
#endif
239
240
}}},
240
241
[DISPATCH_ROOT_QUEUE_IDX_UTILITY_QOS_OVERCOMMIT ] = {{{
241
- #if HAVE_PTHREAD_WORKQUEUES
242
+ #if DISPATCH_USE_WORKQUEUES
242
243
.dgq_qos = QOS_CLASS_UTILITY ,
243
244
.dgq_wq_priority = WORKQ_LOW_PRIOQUEUE ,
244
245
.dgq_wq_options = WORKQ_ADDTHREADS_OPTION_OVERCOMMIT ,
@@ -249,7 +250,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
249
250
#endif
250
251
}}},
251
252
[DISPATCH_ROOT_QUEUE_IDX_DEFAULT_QOS ] = {{{
252
- #if HAVE_PTHREAD_WORKQUEUES
253
+ #if DISPATCH_USE_WORKQUEUES
253
254
.dgq_qos = QOS_CLASS_DEFAULT ,
254
255
.dgq_wq_priority = WORKQ_DEFAULT_PRIOQUEUE ,
255
256
.dgq_wq_options = 0 ,
@@ -260,7 +261,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
260
261
#endif
261
262
}}},
262
263
[DISPATCH_ROOT_QUEUE_IDX_DEFAULT_QOS_OVERCOMMIT ] = {{{
263
- #if HAVE_PTHREAD_WORKQUEUES
264
+ #if DISPATCH_USE_WORKQUEUES
264
265
.dgq_qos = QOS_CLASS_DEFAULT ,
265
266
.dgq_wq_priority = WORKQ_DEFAULT_PRIOQUEUE ,
266
267
.dgq_wq_options = WORKQ_ADDTHREADS_OPTION_OVERCOMMIT ,
@@ -271,7 +272,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
271
272
#endif
272
273
}}},
273
274
[DISPATCH_ROOT_QUEUE_IDX_USER_INITIATED_QOS ] = {{{
274
- #if HAVE_PTHREAD_WORKQUEUES
275
+ #if DISPATCH_USE_WORKQUEUES
275
276
.dgq_qos = QOS_CLASS_USER_INITIATED ,
276
277
.dgq_wq_priority = WORKQ_HIGH_PRIOQUEUE ,
277
278
.dgq_wq_options = 0 ,
@@ -282,7 +283,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
282
283
#endif
283
284
}}},
284
285
[DISPATCH_ROOT_QUEUE_IDX_USER_INITIATED_QOS_OVERCOMMIT ] = {{{
285
- #if HAVE_PTHREAD_WORKQUEUES
286
+ #if DISPATCH_USE_WORKQUEUES
286
287
.dgq_qos = QOS_CLASS_USER_INITIATED ,
287
288
.dgq_wq_priority = WORKQ_HIGH_PRIOQUEUE ,
288
289
.dgq_wq_options = WORKQ_ADDTHREADS_OPTION_OVERCOMMIT ,
@@ -293,7 +294,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
293
294
#endif
294
295
}}},
295
296
[DISPATCH_ROOT_QUEUE_IDX_USER_INTERACTIVE_QOS ] = {{{
296
- #if HAVE_PTHREAD_WORKQUEUES
297
+ #if DISPATCH_USE_WORKQUEUES
297
298
.dgq_qos = QOS_CLASS_USER_INTERACTIVE ,
298
299
.dgq_wq_priority = WORKQ_HIGH_PRIOQUEUE_CONDITIONAL ,
299
300
.dgq_wq_options = 0 ,
@@ -304,7 +305,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
304
305
#endif
305
306
}}},
306
307
[DISPATCH_ROOT_QUEUE_IDX_USER_INTERACTIVE_QOS_OVERCOMMIT ] = {{{
307
- #if HAVE_PTHREAD_WORKQUEUES
308
+ #if DISPATCH_USE_WORKQUEUES
308
309
.dgq_qos = QOS_CLASS_USER_INTERACTIVE ,
309
310
.dgq_wq_priority = WORKQ_HIGH_PRIOQUEUE_CONDITIONAL ,
310
311
.dgq_wq_options = WORKQ_ADDTHREADS_OPTION_OVERCOMMIT ,
@@ -572,11 +573,11 @@ dispatch_assert_queue_barrier(dispatch_queue_t dq)
572
573
static inline bool
573
574
_dispatch_root_queues_init_workq (int * wq_supported )
574
575
{
575
- int r ;
576
+ int r ; ( void ) r ;
576
577
bool result = false;
577
578
* wq_supported = 0 ;
578
- #if HAVE_PTHREAD_WORKQUEUES
579
- bool disable_wq = false;
579
+ #if DISPATCH_USE_WORKQUEUES
580
+ bool disable_wq = false; ( void ) disable_wq ;
580
581
#if DISPATCH_ENABLE_THREAD_POOL && DISPATCH_DEBUG
581
582
disable_wq = slowpath (getenv ("LIBDISPATCH_DISABLE_KWQ" ));
582
583
#endif
@@ -676,7 +677,7 @@ _dispatch_root_queues_init_workq(int *wq_supported)
676
677
#endif
677
678
}
678
679
#endif // DISPATCH_USE_LEGACY_WORKQUEUE_FALLBACK || DISPATCH_ENABLE_THREAD_POOL
679
- #endif // HAVE_PTHREAD_WORKQUEUES
680
+ #endif // DISPATCH_USE_WORKQUEUES
680
681
return result ;
681
682
}
682
683
@@ -692,7 +693,7 @@ _dispatch_root_queue_init_pthread_pool(dispatch_root_queue_context_t qc,
692
693
thread_pool_size = pool_size ;
693
694
}
694
695
qc -> dgq_thread_pool_size = thread_pool_size ;
695
- #if HAVE_PTHREAD_WORKQUEUES
696
+ #if DISPATCH_USE_WORKQUEUES
696
697
if (qc -> dgq_qos ) {
697
698
(void )dispatch_assume_zero (pthread_attr_init (& pqc -> dpq_thread_attr ));
698
699
(void )dispatch_assume_zero (pthread_attr_setdetachstate (
@@ -1906,7 +1907,7 @@ static struct dispatch_pthread_root_queue_context_s
1906
1907
_dispatch_mgr_root_queue_pthread_context ;
1907
1908
static struct dispatch_root_queue_context_s
1908
1909
_dispatch_mgr_root_queue_context = {{{
1909
- #if HAVE_PTHREAD_WORKQUEUES
1910
+ #if DISPATCH_USE_WORKQUEUES
1910
1911
.dgq_kworkqueue = (void * )(~0ul ),
1911
1912
#endif
1912
1913
.dgq_ctxt = & _dispatch_mgr_root_queue_pthread_context ,
@@ -2165,7 +2166,7 @@ _dispatch_pthread_root_queue_create(const char *label, unsigned long flags,
2165
2166
2166
2167
pqc -> dpq_thread_mediator .do_vtable = DISPATCH_VTABLE (semaphore );
2167
2168
qc -> dgq_ctxt = pqc ;
2168
- #if HAVE_PTHREAD_WORKQUEUES
2169
+ #if DISPATCH_USE_WORKQUEUES
2169
2170
qc -> dgq_kworkqueue = (void * )(~0ul );
2170
2171
#endif
2171
2172
_dispatch_root_queue_init_pthread_pool (qc , pool_size , true);
@@ -4378,7 +4379,7 @@ _dispatch_global_queue_poke_slow(dispatch_queue_t dq, int n, int floor)
4378
4379
4379
4380
_dispatch_root_queues_init ();
4380
4381
_dispatch_debug_root_queue (dq , __func__ );
4381
- #if HAVE_PTHREAD_WORKQUEUES
4382
+ #if DISPATCH_USE_WORKQUEUES
4382
4383
#if DISPATCH_USE_PTHREAD_POOL
4383
4384
if (qc -> dgq_kworkqueue != (void * )(~0ul ))
4384
4385
#endif
@@ -4407,7 +4408,7 @@ _dispatch_global_queue_poke_slow(dispatch_queue_t dq, int n, int floor)
4407
4408
(void )dispatch_assume_zero (r );
4408
4409
return ;
4409
4410
}
4410
- #endif // HAVE_PTHREAD_WORKQUEUES
4411
+ #endif // DISPATCH_USE_WORKQUEUES
4411
4412
#if DISPATCH_USE_PTHREAD_POOL
4412
4413
dispatch_pthread_root_queue_context_t pqc = qc -> dgq_ctxt ;
4413
4414
if (fastpath (pqc -> dpq_thread_mediator .do_vtable )) {
@@ -4476,7 +4477,7 @@ _dispatch_global_queue_poke(dispatch_queue_t dq, int n, int floor)
4476
4477
if (!_dispatch_queue_class_probe (dq )) {
4477
4478
return ;
4478
4479
}
4479
- #if HAVE_PTHREAD_WORKQUEUES
4480
+ #if DISPATCH_USE_WORKQUEUES
4480
4481
dispatch_root_queue_context_t qc = dq -> do_ctxt ;
4481
4482
if (
4482
4483
#if DISPATCH_USE_PTHREAD_POOL
@@ -4487,7 +4488,7 @@ _dispatch_global_queue_poke(dispatch_queue_t dq, int n, int floor)
4487
4488
"global queue: %p" , dq );
4488
4489
return ;
4489
4490
}
4490
- #endif // HAVE_PTHREAD_WORKQUEUES
4491
+ #endif // DISPATCH_USE_WORKQUEUES
4491
4492
return _dispatch_global_queue_poke_slow (dq , n , floor );
4492
4493
}
4493
4494
0 commit comments