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
@@ -151,13 +152,13 @@ struct dispatch_root_queue_context_s {
151
152
union {
152
153
struct {
153
154
int volatile dgq_pending ;
154
- #if HAVE_PTHREAD_WORKQUEUES
155
+ #if DISPATCH_USE_WORKQUEUES
155
156
qos_class_t dgq_qos ;
156
157
int dgq_wq_priority , dgq_wq_options ;
157
158
#if DISPATCH_USE_LEGACY_WORKQUEUE_FALLBACK || DISPATCH_USE_PTHREAD_POOL
158
159
pthread_workqueue_t dgq_kworkqueue ;
159
160
#endif
160
- #endif // HAVE_PTHREAD_WORKQUEUES
161
+ #endif // DISPATCH_USE_WORKQUEUES
161
162
#if DISPATCH_USE_PTHREAD_POOL
162
163
void * dgq_ctxt ;
163
164
int32_t volatile dgq_thread_pool_size ;
@@ -179,7 +180,7 @@ typedef struct dispatch_root_queue_context_s *dispatch_root_queue_context_t;
179
180
DISPATCH_CACHELINE_ALIGN
180
181
static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts [] = {
181
182
[DISPATCH_ROOT_QUEUE_IDX_MAINTENANCE_QOS ] = {{{
182
- #if HAVE_PTHREAD_WORKQUEUES
183
+ #if DISPATCH_USE_WORKQUEUES
183
184
.dgq_qos = QOS_CLASS_MAINTENANCE ,
184
185
.dgq_wq_priority = WORKQ_BG_PRIOQUEUE ,
185
186
.dgq_wq_options = 0 ,
@@ -190,7 +191,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
190
191
#endif
191
192
}}},
192
193
[DISPATCH_ROOT_QUEUE_IDX_MAINTENANCE_QOS_OVERCOMMIT ] = {{{
193
- #if HAVE_PTHREAD_WORKQUEUES
194
+ #if DISPATCH_USE_WORKQUEUES
194
195
.dgq_qos = QOS_CLASS_MAINTENANCE ,
195
196
.dgq_wq_priority = WORKQ_BG_PRIOQUEUE ,
196
197
.dgq_wq_options = WORKQ_ADDTHREADS_OPTION_OVERCOMMIT ,
@@ -201,7 +202,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
201
202
#endif
202
203
}}},
203
204
[DISPATCH_ROOT_QUEUE_IDX_BACKGROUND_QOS ] = {{{
204
- #if HAVE_PTHREAD_WORKQUEUES
205
+ #if DISPATCH_USE_WORKQUEUES
205
206
.dgq_qos = QOS_CLASS_BACKGROUND ,
206
207
.dgq_wq_priority = WORKQ_BG_PRIOQUEUE_CONDITIONAL ,
207
208
.dgq_wq_options = 0 ,
@@ -212,7 +213,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
212
213
#endif
213
214
}}},
214
215
[DISPATCH_ROOT_QUEUE_IDX_BACKGROUND_QOS_OVERCOMMIT ] = {{{
215
- #if HAVE_PTHREAD_WORKQUEUES
216
+ #if DISPATCH_USE_WORKQUEUES
216
217
.dgq_qos = QOS_CLASS_BACKGROUND ,
217
218
.dgq_wq_priority = WORKQ_BG_PRIOQUEUE_CONDITIONAL ,
218
219
.dgq_wq_options = WORKQ_ADDTHREADS_OPTION_OVERCOMMIT ,
@@ -223,7 +224,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
223
224
#endif
224
225
}}},
225
226
[DISPATCH_ROOT_QUEUE_IDX_UTILITY_QOS ] = {{{
226
- #if HAVE_PTHREAD_WORKQUEUES
227
+ #if DISPATCH_USE_WORKQUEUES
227
228
.dgq_qos = QOS_CLASS_UTILITY ,
228
229
.dgq_wq_priority = WORKQ_LOW_PRIOQUEUE ,
229
230
.dgq_wq_options = 0 ,
@@ -234,7 +235,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
234
235
#endif
235
236
}}},
236
237
[DISPATCH_ROOT_QUEUE_IDX_UTILITY_QOS_OVERCOMMIT ] = {{{
237
- #if HAVE_PTHREAD_WORKQUEUES
238
+ #if DISPATCH_USE_WORKQUEUES
238
239
.dgq_qos = QOS_CLASS_UTILITY ,
239
240
.dgq_wq_priority = WORKQ_LOW_PRIOQUEUE ,
240
241
.dgq_wq_options = WORKQ_ADDTHREADS_OPTION_OVERCOMMIT ,
@@ -245,7 +246,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
245
246
#endif
246
247
}}},
247
248
[DISPATCH_ROOT_QUEUE_IDX_DEFAULT_QOS ] = {{{
248
- #if HAVE_PTHREAD_WORKQUEUES
249
+ #if DISPATCH_USE_WORKQUEUES
249
250
.dgq_qos = QOS_CLASS_DEFAULT ,
250
251
.dgq_wq_priority = WORKQ_DEFAULT_PRIOQUEUE ,
251
252
.dgq_wq_options = 0 ,
@@ -256,7 +257,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
256
257
#endif
257
258
}}},
258
259
[DISPATCH_ROOT_QUEUE_IDX_DEFAULT_QOS_OVERCOMMIT ] = {{{
259
- #if HAVE_PTHREAD_WORKQUEUES
260
+ #if DISPATCH_USE_WORKQUEUES
260
261
.dgq_qos = QOS_CLASS_DEFAULT ,
261
262
.dgq_wq_priority = WORKQ_DEFAULT_PRIOQUEUE ,
262
263
.dgq_wq_options = WORKQ_ADDTHREADS_OPTION_OVERCOMMIT ,
@@ -267,7 +268,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
267
268
#endif
268
269
}}},
269
270
[DISPATCH_ROOT_QUEUE_IDX_USER_INITIATED_QOS ] = {{{
270
- #if HAVE_PTHREAD_WORKQUEUES
271
+ #if DISPATCH_USE_WORKQUEUES
271
272
.dgq_qos = QOS_CLASS_USER_INITIATED ,
272
273
.dgq_wq_priority = WORKQ_HIGH_PRIOQUEUE ,
273
274
.dgq_wq_options = 0 ,
@@ -278,7 +279,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
278
279
#endif
279
280
}}},
280
281
[DISPATCH_ROOT_QUEUE_IDX_USER_INITIATED_QOS_OVERCOMMIT ] = {{{
281
- #if HAVE_PTHREAD_WORKQUEUES
282
+ #if DISPATCH_USE_WORKQUEUES
282
283
.dgq_qos = QOS_CLASS_USER_INITIATED ,
283
284
.dgq_wq_priority = WORKQ_HIGH_PRIOQUEUE ,
284
285
.dgq_wq_options = WORKQ_ADDTHREADS_OPTION_OVERCOMMIT ,
@@ -289,7 +290,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
289
290
#endif
290
291
}}},
291
292
[DISPATCH_ROOT_QUEUE_IDX_USER_INTERACTIVE_QOS ] = {{{
292
- #if HAVE_PTHREAD_WORKQUEUES
293
+ #if DISPATCH_USE_WORKQUEUES
293
294
.dgq_qos = QOS_CLASS_USER_INTERACTIVE ,
294
295
.dgq_wq_priority = WORKQ_HIGH_PRIOQUEUE_CONDITIONAL ,
295
296
.dgq_wq_options = 0 ,
@@ -300,7 +301,7 @@ static struct dispatch_root_queue_context_s _dispatch_root_queue_contexts[] = {
300
301
#endif
301
302
}}},
302
303
[DISPATCH_ROOT_QUEUE_IDX_USER_INTERACTIVE_QOS_OVERCOMMIT ] = {{{
303
- #if HAVE_PTHREAD_WORKQUEUES
304
+ #if DISPATCH_USE_WORKQUEUES
304
305
.dgq_qos = QOS_CLASS_USER_INTERACTIVE ,
305
306
.dgq_wq_priority = WORKQ_HIGH_PRIOQUEUE_CONDITIONAL ,
306
307
.dgq_wq_options = WORKQ_ADDTHREADS_OPTION_OVERCOMMIT ,
@@ -576,11 +577,11 @@ dispatch_assert_queue_barrier(dispatch_queue_t dq)
576
577
static inline bool
577
578
_dispatch_root_queues_init_workq (int * wq_supported )
578
579
{
579
- int r ;
580
+ int r ; ( void ) r ;
580
581
bool result = false;
581
582
* wq_supported = 0 ;
582
- #if HAVE_PTHREAD_WORKQUEUES
583
- bool disable_wq = false;
583
+ #if DISPATCH_USE_WORKQUEUES
584
+ bool disable_wq = false; ( void ) disable_wq ;
584
585
#if DISPATCH_ENABLE_THREAD_POOL && DISPATCH_DEBUG
585
586
disable_wq = slowpath (getenv ("LIBDISPATCH_DISABLE_KWQ" ));
586
587
#endif
@@ -683,7 +684,7 @@ _dispatch_root_queues_init_workq(int *wq_supported)
683
684
#endif
684
685
}
685
686
#endif // DISPATCH_USE_LEGACY_WORKQUEUE_FALLBACK || DISPATCH_ENABLE_THREAD_POOL
686
- #endif // HAVE_PTHREAD_WORKQUEUES
687
+ #endif // DISPATCH_USE_WORKQUEUES
687
688
return result ;
688
689
}
689
690
@@ -699,7 +700,7 @@ _dispatch_root_queue_init_pthread_pool(dispatch_root_queue_context_t qc,
699
700
thread_pool_size = pool_size ;
700
701
}
701
702
qc -> dgq_thread_pool_size = thread_pool_size ;
702
- #if HAVE_PTHREAD_WORKQUEUES
703
+ #if DISPATCH_USE_WORKQUEUES
703
704
if (qc -> dgq_qos ) {
704
705
(void )dispatch_assume_zero (pthread_attr_init (& pqc -> dpq_thread_attr ));
705
706
(void )dispatch_assume_zero (pthread_attr_setdetachstate (
@@ -1757,7 +1758,7 @@ static struct dispatch_pthread_root_queue_context_s
1757
1758
_dispatch_mgr_root_queue_pthread_context ;
1758
1759
static struct dispatch_root_queue_context_s
1759
1760
_dispatch_mgr_root_queue_context = {{{
1760
- #if HAVE_PTHREAD_WORKQUEUES
1761
+ #if DISPATCH_USE_WORKQUEUES
1761
1762
.dgq_kworkqueue = (void * )(~0ul ),
1762
1763
#endif
1763
1764
.dgq_ctxt = & _dispatch_mgr_root_queue_pthread_context ,
@@ -2019,7 +2020,7 @@ _dispatch_pthread_root_queue_create(const char *label, unsigned long flags,
2019
2020
2020
2021
pqc -> dpq_thread_mediator .do_vtable = DISPATCH_VTABLE (semaphore );
2021
2022
qc -> dgq_ctxt = pqc ;
2022
- #if HAVE_PTHREAD_WORKQUEUES
2023
+ #if DISPATCH_USE_WORKQUEUES
2023
2024
qc -> dgq_kworkqueue = (void * )(~0ul );
2024
2025
#endif
2025
2026
_dispatch_root_queue_init_pthread_pool (qc , pool_size , true);
@@ -3963,7 +3964,7 @@ _dispatch_global_queue_poke_slow(dispatch_queue_t dq, int n, int floor)
3963
3964
3964
3965
_dispatch_root_queues_init ();
3965
3966
_dispatch_debug_root_queue (dq , __func__ );
3966
- #if HAVE_PTHREAD_WORKQUEUES
3967
+ #if DISPATCH_USE_WORKQUEUES
3967
3968
#if DISPATCH_USE_PTHREAD_POOL
3968
3969
if (qc -> dgq_kworkqueue != (void * )(~0ul ))
3969
3970
#endif
@@ -3992,7 +3993,7 @@ _dispatch_global_queue_poke_slow(dispatch_queue_t dq, int n, int floor)
3992
3993
(void )dispatch_assume_zero (r );
3993
3994
return ;
3994
3995
}
3995
- #endif // HAVE_PTHREAD_WORKQUEUES
3996
+ #endif // DISPATCH_USE_WORKQUEUES
3996
3997
#if DISPATCH_USE_PTHREAD_POOL
3997
3998
dispatch_pthread_root_queue_context_t pqc = qc -> dgq_ctxt ;
3998
3999
if (fastpath (pqc -> dpq_thread_mediator .do_vtable )) {
@@ -4061,7 +4062,7 @@ _dispatch_global_queue_poke(dispatch_queue_t dq, int n, int floor)
4061
4062
if (!_dispatch_queue_class_probe (dq )) {
4062
4063
return ;
4063
4064
}
4064
- #if HAVE_PTHREAD_WORKQUEUES
4065
+ #if DISPATCH_USE_WORKQUEUES
4065
4066
dispatch_root_queue_context_t qc = dq -> do_ctxt ;
4066
4067
if (
4067
4068
#if DISPATCH_USE_PTHREAD_POOL
@@ -4072,7 +4073,7 @@ _dispatch_global_queue_poke(dispatch_queue_t dq, int n, int floor)
4072
4073
"global queue: %p" , dq );
4073
4074
return ;
4074
4075
}
4075
- #endif // HAVE_PTHREAD_WORKQUEUES
4076
+ #endif // DISPATCH_USE_WORKQUEUES
4076
4077
return _dispatch_global_queue_poke_slow (dq , n , floor );
4077
4078
}
4078
4079
0 commit comments