Skip to content

Commit 7f2a683

Browse files
committed
tweaks to preprocessor checks in libdispatch-685 Linux port
validated by building on Darwin with -DHAVE_PTHREAD_WORKQUEUE_QOS=0 -DDISPATCH_USE_KEVENT_QOS=0 -DVOUCHER_USE_MACH_VOUCHER=0 -DOS_FIREHOSE_SPI=0 Signed-off-by: Daniel A. Steffen <[email protected]>
1 parent 847f62b commit 7f2a683

File tree

10 files changed

+43
-68
lines changed

10 files changed

+43
-68
lines changed

config/config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
don't. */
1414
#define HAVE_DECL_FD_COPY 1
1515

16+
/* Define to 1 if you have the declaration of `NOTE_LOWAT', and to 0 if you
17+
don't. */
18+
#define HAVE_DECL_NOTE_LOWAT 1
19+
1620
/* Define to 1 if you have the declaration of `NOTE_NONE', and to 0 if you
1721
don't. */
1822
#define HAVE_DECL_NOTE_NONE 1

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ AC_CHECK_FUNCS([mach_port_construct])
267267
#
268268
AC_CHECK_DECLS([CLOCK_UPTIME, CLOCK_MONOTONIC], [], [],
269269
[[#include <time.h>]])
270-
AC_CHECK_DECLS([NOTE_NONE, NOTE_REAP, NOTE_REVOKE, NOTE_SIGNAL], [], [],
270+
AC_CHECK_DECLS([NOTE_NONE, NOTE_REAP, NOTE_REVOKE, NOTE_SIGNAL, NOTE_LOWAT], [], [],
271271
[[#include <sys/event.h>]])
272272
AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]])
273273
AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]])

dispatch/dispatch.h

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,53 +24,31 @@
2424
#ifdef __APPLE__
2525
#include <Availability.h>
2626
#include <TargetConditionals.h>
27-
#endif
28-
#include <sys/cdefs.h>
29-
#include <sys/types.h>
30-
#include <stddef.h>
31-
#include <stdint.h>
32-
#include <stdbool.h>
33-
#include <stdarg.h>
34-
#include <unistd.h>
35-
#include <fcntl.h>
36-
37-
#if defined(__linux__) && defined(__DISPATCH_BUILDING_SWIFT_MODULE__)
38-
#include <stdio.h> // for off_t
39-
#endif
40-
41-
#ifndef __OSX_AVAILABLE_STARTING
27+
#else
4228
#define __OSX_AVAILABLE_STARTING(x, y)
43-
#endif
44-
#ifndef __OSX_AVAILABLE_BUT_DEPRECATED
4529
#define __OSX_AVAILABLE_BUT_DEPRECATED(...)
46-
#endif
47-
#ifndef __OSX_AVAILABLE_BUT_DEPRECATED_MSG
4830
#define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(...)
49-
#endif
50-
51-
#ifndef __OSX_AVAILABLE
5231
#define __OSX_AVAILABLE(...)
53-
#endif
54-
#ifndef __IOS_AVAILABLE
5532
#define __IOS_AVAILABLE(...)
56-
#endif
57-
#ifndef __TVOS_AVAILABLE
5833
#define __TVOS_AVAILABLE(...)
59-
#endif
60-
#ifndef __WATCHOS_AVAILABLE
6134
#define __WATCHOS_AVAILABLE(...)
62-
#endif
63-
#ifndef __OSX_DEPRECATED
6435
#define __OSX_DEPRECATED(...)
65-
#endif
66-
#ifndef __IOS_DEPRECATED
6736
#define __IOS_DEPRECATED(...)
68-
#endif
69-
#ifndef __TVOS_DEPRECATED
7037
#define __TVOS_DEPRECATED(...)
71-
#endif
72-
#ifndef __WATCHOS_DEPRECATED
7338
#define __WATCHOS_DEPRECATED(...)
39+
#endif // __APPLE__
40+
41+
#include <sys/cdefs.h>
42+
#include <sys/types.h>
43+
#include <stddef.h>
44+
#include <stdint.h>
45+
#include <stdbool.h>
46+
#include <stdarg.h>
47+
#include <unistd.h>
48+
#include <fcntl.h>
49+
50+
#if defined(__linux__) && defined(__DISPATCH_BUILDING_SWIFT_MODULE__)
51+
#include <stdio.h> // for off_t
7452
#endif
7553

7654
#define DISPATCH_API_VERSION 20160612

src/firehose/firehose_buffer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ static void _dispatch_gate_wait(dispatch_gate_t l, uint32_t flags);
8383
#include "firehose_replyServer.h" // MiG
8484
#endif
8585

86+
#if OS_FIREHOSE_SPI
87+
8688
#if __has_feature(c_static_assert)
8789
_Static_assert(sizeof(((firehose_stream_state_u *)NULL)->fss_gate) ==
8890
sizeof(((firehose_stream_state_u *)NULL)->fss_allocator),
@@ -1141,3 +1143,5 @@ __firehose_merge_updates(firehose_push_reply_t update)
11411143
}
11421144
}
11431145
#endif // KERNEL
1146+
1147+
#endif // OS_FIREHOSE_SPI

src/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,8 +1196,8 @@ dispatch_source_type_readwrite_init(dispatch_source_t ds,
11961196
dispatch_queue_t q DISPATCH_UNUSED)
11971197
{
11981198
ds->ds_is_level = true;
1199+
#ifdef HAVE_DECL_NOTE_LOWAT
11991200
// bypass kernel check for device kqueue support rdar://19004921
1200-
#ifdef NOTE_LOWAT
12011201
ds->ds_dkev->dk_kevent.fflags = NOTE_LOWAT;
12021202
#endif
12031203
ds->ds_dkev->dk_kevent.data = 1;

src/inline_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,7 @@ _dispatch_set_defaultpriority(pthread_priority_t pp, pthread_priority_t *new_pp)
19631963
if (new_pp) *new_pp = pp;
19641964
return old_pp;
19651965
#else
1966-
(void)pp;
1966+
(void)pp; (void)new_pp;
19671967
return 0;
19681968
#endif
19691969
}

src/internal.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -938,16 +938,6 @@ _dispatch_ktrace_impl(uint32_t code, uint64_t a, uint64_t b,
938938
#define VOUCHER_USE_BANK_AUTOREDEEM 1
939939
#endif
940940

941-
#if OS_FIREHOSE_SPI
942-
#include <firehose/private.h>
943-
#else
944-
typedef uint64_t firehose_activity_id_t;
945-
typedef uint64_t firehose_tracepoint_id_t;
946-
typedef unsigned long firehose_activity_flags_t;
947-
typedef uint8_t firehose_stream_t;
948-
typedef void * voucher_activity_hooks_t;
949-
#endif
950-
951941
#if !VOUCHER_USE_MACH_VOUCHER || \
952942
!__has_include(<voucher/ipc_pthread_priority_types.h>) || \
953943
!DISPATCH_HOST_SUPPORTS_OSX(101200)

src/introspection.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ _dispatch_introspection_continuation_get_info(dispatch_queue_t dq,
189189
if (_dispatch_object_has_vtable(dc)) {
190190
flags = 0;
191191
switch (dc_type(dc)) {
192+
#if HAVE_PTHREAD_WORKQUEUE_QOS
192193
case DC_OVERRIDE_STEALING_TYPE:
193194
case DC_OVERRIDE_OWNING_TYPE:
194195
dc = dc->dc_data;
@@ -200,6 +201,7 @@ _dispatch_introspection_continuation_get_info(dispatch_queue_t dq,
200201
return;
201202
}
202203
return _dispatch_introspection_continuation_get_info(dq, dc, diqi);
204+
#endif
203205
case DC_ASYNC_REDIRECT_TYPE:
204206
DISPATCH_INTERNAL_CRASH(0, "Handled by the caller");
205207
case DC_MACH_SEND_BARRRIER_DRAIN_TYPE:

src/queue.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,7 +2658,6 @@ _dispatch_block_create_with_voucher_and_priority(dispatch_block_flags_t flags,
26582658
voucher_t voucher, pthread_priority_t pri, dispatch_block_t block)
26592659
{
26602660
flags = _dispatch_block_normalize_flags(flags);
2661-
#if HAVE_PTHREAD_WORKQUEUE_QOS
26622661
bool assign = (flags & DISPATCH_BLOCK_ASSIGN_CURRENT);
26632662

26642663
if (assign && !(flags & DISPATCH_BLOCK_HAS_VOUCHER)) {
@@ -2672,7 +2671,6 @@ _dispatch_block_create_with_voucher_and_priority(dispatch_block_flags_t flags,
26722671
pri = _dispatch_priority_propagate();
26732672
flags |= DISPATCH_BLOCK_HAS_PRIORITY;
26742673
}
2675-
#endif
26762674
dispatch_block_t db = _dispatch_block_create(flags, voucher, pri, block);
26772675
#if DISPATCH_DEBUG
26782676
dispatch_assert(_dispatch_block_get_data(db));
@@ -3995,20 +3993,18 @@ _dispatch_queue_wakeup(dispatch_queue_t dq, pthread_priority_t pp,
39953993
}
39963994
if (target) {
39973995
return _dispatch_queue_class_wakeup(dq, pp, flags, target);
3998-
#if HAVE_PTHREAD_WORKQUEUE_QOS
39993996
} else if (pp) {
40003997
return _dispatch_queue_class_override_drainer(dq, pp, flags);
4001-
#endif
40023998
} else if (flags & DISPATCH_WAKEUP_CONSUME) {
40033999
return _dispatch_release_tailcall(dq);
40044000
}
40054001
}
40064002

4007-
#if DISPATCH_COCOA_COMPAT
40084003
void
40094004
_dispatch_runloop_queue_wakeup(dispatch_queue_t dq, pthread_priority_t pp,
40104005
dispatch_wakeup_flags_t flags)
40114006
{
4007+
#if DISPATCH_COCOA_COMPAT
40124008
if (slowpath(_dispatch_queue_atomic_flags(dq) & DQF_RELEASED)) {
40134009
// <rdar://problem/14026816>
40144010
return _dispatch_queue_wakeup(dq, pp, flags);
@@ -4027,19 +4023,15 @@ _dispatch_runloop_queue_wakeup(dispatch_queue_t dq, pthread_priority_t pp,
40274023
_dispatch_thread_override_end(owner, dq);
40284024
return;
40294025
}
4030-
40314026
if (flags & DISPATCH_WAKEUP_CONSUME) {
40324027
return _dispatch_release_tailcall(dq);
40334028
}
4034-
}
4035-
#else
4036-
void
4037-
_dispatch_runloop_queue_wakeup(dispatch_queue_t dq, pthread_priority_t pp,
4038-
dispatch_wakeup_flags_t flags)
4039-
{
4029+
#elif defined(__linux__)
40404030
LINUX_PORT_ERROR();
4041-
}
4031+
#else
4032+
return _dispatch_queue_wakeup(dq, pp, flags);
40424033
#endif
4034+
}
40434035

40444036
void
40454037
_dispatch_main_queue_wakeup(dispatch_queue_t dq, pthread_priority_t pp,
@@ -4930,12 +4922,14 @@ _dispatch_queue_class_wakeup_with_override(dispatch_queue_t dq,
49304922
return _dispatch_release_tailcall(dq);
49314923
}
49324924
}
4925+
#endif // HAVE_PTHREAD_WORKQUEUE_QOS
49334926

49344927
DISPATCH_NOINLINE
49354928
void
49364929
_dispatch_queue_class_override_drainer(dispatch_queue_t dq,
49374930
pthread_priority_t pp, dispatch_wakeup_flags_t flags)
49384931
{
4932+
#if HAVE_PTHREAD_WORKQUEUE_QOS
49394933
uint64_t dq_state, value;
49404934

49414935
//
@@ -4957,10 +4951,14 @@ _dispatch_queue_class_override_drainer(dispatch_queue_t dq,
49574951
return _dispatch_queue_class_wakeup_with_override(dq, pp,
49584952
flags, dq_state);
49594953
}
4954+
#else
4955+
(void)pp;
4956+
#endif // HAVE_PTHREAD_WORKQUEUE_QOS
49604957
if (flags & DISPATCH_WAKEUP_CONSUME) {
49614958
return _dispatch_release_tailcall(dq);
49624959
}
49634960
}
4961+
49644962
#if DISPATCH_USE_KEVENT_WORKQUEUE
49654963
DISPATCH_NOINLINE
49664964
static void
@@ -4997,7 +4995,6 @@ _dispatch_trystash_to_deferred_items(dispatch_queue_t dq, dispatch_object_t dou,
49974995
_dispatch_queue_push_inline(dq, dou, 0, 0);
49984996
}
49994997
#endif
5000-
#endif // HAVE_PTHREAD_WORKQUEUE_QOS
50014998

50024999
DISPATCH_NOINLINE
50035000
void

src/source.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,10 +1031,8 @@ _dispatch_source_wakeup(dispatch_source_t ds, pthread_priority_t pp,
10311031

10321032
if (tq) {
10331033
return _dispatch_queue_class_wakeup(ds->_as_dq, pp, flags, tq);
1034-
#if HAVE_PTHREAD_WORKQUEUE_QOS
10351034
} else if (pp) {
10361035
return _dispatch_queue_class_override_drainer(ds->_as_dq, pp, flags);
1037-
#endif
10381036
} else if (flags & DISPATCH_WAKEUP_CONSUME) {
10391037
return _dispatch_release_tailcall(ds);
10401038
}
@@ -3192,19 +3190,23 @@ _dispatch_memorypressure_handler(void *context DISPATCH_UNUSED)
31923190
if (memorypressure & DISPATCH_MEMORYPRESSURE_NORMAL) {
31933191
_dispatch_memory_warn = false;
31943192
_dispatch_continuation_cache_limit = DISPATCH_CONTINUATION_CACHE_LIMIT;
3193+
#if VOUCHER_USE_MACH_VOUCHER
31953194
if (_firehose_task_buffer) {
31963195
firehose_buffer_clear_bank_flags(_firehose_task_buffer,
31973196
FIREHOSE_BUFFER_BANK_FLAG_LOW_MEMORY);
31983197
}
3198+
#endif
31993199
}
32003200
if (memorypressure & DISPATCH_MEMORYPRESSURE_WARN) {
32013201
_dispatch_memory_warn = true;
32023202
_dispatch_continuation_cache_limit =
32033203
DISPATCH_CONTINUATION_CACHE_LIMIT_MEMORYPRESSURE_PRESSURE_WARN;
3204+
#if VOUCHER_USE_MACH_VOUCHER
32043205
if (_firehose_task_buffer) {
32053206
firehose_buffer_set_bank_flags(_firehose_task_buffer,
32063207
FIREHOSE_BUFFER_BANK_FLAG_LOW_MEMORY);
32073208
}
3209+
#endif
32083210
}
32093211
if (memorypressure & DISPATCH_MEMORYPRESSURE_MALLOC_MASK) {
32103212
malloc_memory_event_handler(memorypressure & DISPATCH_MEMORYPRESSURE_MALLOC_MASK);
@@ -6086,10 +6088,8 @@ _dispatch_mach_wakeup(dispatch_mach_t dm, pthread_priority_t pp,
60866088
done:
60876089
if (tq) {
60886090
return _dispatch_queue_class_wakeup(dm->_as_dq, pp, flags, tq);
6089-
#if HAVE_PTHREAD_WORKQUEUE_QOS
60906091
} else if (pp) {
60916092
return _dispatch_queue_class_override_drainer(dm->_as_dq, pp, flags);
6092-
#endif
60936093
} else if (flags & DISPATCH_WAKEUP_CONSUME) {
60946094
return _dispatch_release_tailcall(dm);
60956095
}
@@ -6585,7 +6585,7 @@ dispatch_kevent_debug(const char *verb, const _dispatch_kevent_qos_s *kev,
65856585
#else
65866586
0ull, 0ull,
65876587
#endif
6588-
str, function, line);
6588+
function, line);
65896589
#endif
65906590
}
65916591

0 commit comments

Comments
 (0)