Skip to content

Commit e948f91

Browse files
sprinkle the source with HAVE_MACH
1 parent 94b0fe8 commit e948f91

File tree

9 files changed

+34
-37
lines changed

9 files changed

+34
-37
lines changed

private/voucher_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ dispatch_queue_create_with_accounting_override_voucher(const char *label,
404404

405405
#ifdef __APPLE__
406406
#include <mach/mach.h>
407-
#endif
408407

409408
/*!
410409
* @function voucher_create_with_mach_msg
@@ -428,6 +427,7 @@ OS_VOUCHER_EXPORT OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NOTHROW
428427
voucher_t
429428
voucher_create_with_mach_msg(mach_msg_header_t *msg);
430429

430+
#endif
431431
__END_DECLS
432432

433433
#endif // __OS_VOUCHER_PRIVATE__

src/init.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ DISPATCH_VTABLE_INSTANCE(source,
335335
.do_debug = _dispatch_source_debug,
336336
);
337337

338+
#if HAVE_MACH
338339
DISPATCH_VTABLE_INSTANCE(mach,
339340
.do_type = DISPATCH_MACH_CHANNEL_TYPE,
340341
.do_kind = "mach-channel",
@@ -351,6 +352,7 @@ DISPATCH_VTABLE_INSTANCE(mach_msg,
351352
.do_invoke = _dispatch_mach_msg_invoke,
352353
.do_debug = _dispatch_mach_msg_debug,
353354
);
355+
#endif
354356

355357
#if !USE_OBJC
356358
DISPATCH_VTABLE_INSTANCE(data,
@@ -793,6 +795,7 @@ _dispatch_client_callout2(void *ctxt, size_t i, void (*f)(void *, size_t))
793795
_dispatch_set_unwind_tsd(u);
794796
}
795797

798+
#if HAVE_MACH
796799
#undef _dispatch_client_callout4
797800
void
798801
_dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
@@ -807,6 +810,7 @@ _dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
807810
_dispatch_free_unwind_tsd();
808811
_dispatch_set_unwind_tsd(u);
809812
}
813+
#endif
810814

811815
#endif // DISPATCH_USE_CLIENT_CALLOUT
812816

src/inline_internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ DISPATCH_NOTHROW void
3838
_dispatch_client_callout(void *ctxt, dispatch_function_t f);
3939
DISPATCH_NOTHROW void
4040
_dispatch_client_callout2(void *ctxt, size_t i, void (*f)(void *, size_t));
41+
#if HAVE_MACH
4142
DISPATCH_NOTHROW void
4243
_dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
4344
dispatch_mach_msg_t dmsg, mach_error_t error,
4445
dispatch_mach_handler_function_t f);
46+
#endif
4547

4648
#else // !DISPATCH_USE_CLIENT_CALLOUT
4749

@@ -59,6 +61,7 @@ _dispatch_client_callout2(void *ctxt, size_t i, void (*f)(void *, size_t))
5961
return f(ctxt, i);
6062
}
6163

64+
#if HAVE_MACH
6265
DISPATCH_ALWAYS_INLINE
6366
static inline void
6467
_dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
@@ -67,6 +70,7 @@ _dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
6770
{
6871
return f(ctxt, reason, dmsg, error);
6972
}
73+
#endif
7074

7175
#endif // !DISPATCH_USE_CLIENT_CALLOUT
7276

src/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,10 @@ DISPATCH_NOINLINE
324324
void _dispatch_bug_client(const char* msg);
325325
DISPATCH_NOINLINE
326326
void _dispatch_bug_mach_client(const char *msg, mach_msg_return_t kr);
327+
#endif
327328
DISPATCH_NOINLINE
328329
void _dispatch_bug_kevent_client(const char* msg, const char* filter,
329330
const char *operation, int err);
330-
#endif
331331

332332
DISPATCH_NOINLINE DISPATCH_NORETURN
333333
void _dispatch_abort(size_t line, long val);

src/object.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ - (NSString *)debugDescription {
524524
}
525525
}
526526

527+
#if HAVE_MACH
527528
#undef _dispatch_client_callout4
528529
void
529530
_dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
@@ -537,6 +538,7 @@ - (NSString *)debugDescription {
537538
objc_terminate();
538539
}
539540
}
541+
#endif
540542

541543
#endif // DISPATCH_USE_CLIENT_CALLOUT
542544

src/queue.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@ _dispatch_root_queue_init_pthread_pool(dispatch_root_queue_context_t qc,
858858
thread_pool_size = pool_size;
859859
}
860860
qc->dgq_thread_pool_size = thread_pool_size;
861+
#if HAVE_PTHREAD_WORKQUEUES
861862
if (qc->dgq_qos) {
862863
(void)dispatch_assume_zero(pthread_attr_init(&pqc->dpq_thread_attr));
863864
(void)dispatch_assume_zero(pthread_attr_setdetachstate(
@@ -867,6 +868,7 @@ _dispatch_root_queue_init_pthread_pool(dispatch_root_queue_context_t qc,
867868
&pqc->dpq_thread_attr, qc->dgq_qos, 0));
868869
#endif
869870
}
871+
#endif
870872
#if USE_MACH_SEM
871873
// override the default FIFO behavior for the pool semaphores
872874
kern_return_t kr = semaphore_create(mach_task_self(),
@@ -1464,6 +1466,7 @@ static dispatch_once_t _dispatch_mgr_sched_pred;
14641466

14651467
// TODO: switch to "event-reflector thread" property <rdar://problem/18126138>
14661468

1469+
#if HAVE_PTHREAD_WORKQUEUE_QOS
14671470
// Must be kept in sync with list of qos classes in sys/qos.h
14681471
static const int _dispatch_mgr_sched_qos2prio[] = {
14691472
[_DISPATCH_QOS_CLASS_MAINTENANCE] = 4,
@@ -1473,6 +1476,7 @@ static const int _dispatch_mgr_sched_qos2prio[] = {
14731476
[_DISPATCH_QOS_CLASS_USER_INITIATED] = 37,
14741477
[_DISPATCH_QOS_CLASS_USER_INTERACTIVE] = 47,
14751478
};
1479+
#endif
14761480

14771481
static void
14781482
_dispatch_mgr_sched_init(void *ctxt DISPATCH_UNUSED)
@@ -4056,7 +4060,7 @@ _dispatch_queue_push_override(dispatch_queue_t dq, dispatch_queue_t tq,
40564060

40574061
_dispatch_queue_push(rq, dc, 0);
40584062
#else
4059-
(void)dq; (void)tq; (void)p;
4063+
(void)dq; (void)tq; (void)p; (void)owning;
40604064
#endif
40614065
}
40624066

src/shims/linux_stubs.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525

2626
#include <stdint.h>
27-
27+
#include <syscall.h>
2828
#include <config/config.h>
2929

3030
#include "pthread.h"
@@ -35,44 +35,22 @@
3535
#undef LINUX_PORT_ERROR
3636
#define LINUX_PORT_ERROR() do { printf("LINUX_PORT_ERROR_CALLED %s:%d: %s\n",__FILE__,__LINE__,__FUNCTION__); abort(); } while (0)
3737

38-
void _dispatch_mach_msg_dispose() { LINUX_PORT_ERROR(); }
39-
40-
unsigned long _dispatch_mach_probe(dispatch_mach_t dm) {
41-
LINUX_PORT_ERROR();
42-
}
43-
4438
dispatch_block_t _dispatch_block_create(dispatch_block_flags_t flags,
4539
voucher_t voucher, pthread_priority_t priority,
4640
dispatch_block_t block) {
4741
LINUX_PORT_ERROR();
4842
}
4943

50-
void _dispatch_mach_invoke() { LINUX_PORT_ERROR(); }
51-
52-
size_t _dispatch_mach_msg_debug(dispatch_mach_msg_t dmsg, char* buf, size_t bufsiz) {
53-
LINUX_PORT_ERROR();
54-
}
55-
void _dispatch_mach_dispose() { LINUX_PORT_ERROR(); }
56-
void _dispatch_mach_msg_invoke() { LINUX_PORT_ERROR(); }
57-
5844
unsigned long _dispatch_runloop_queue_probe(dispatch_queue_t dq) {
5945
LINUX_PORT_ERROR();
6046
}
6147
void _dispatch_runloop_queue_xref_dispose() { LINUX_PORT_ERROR(); }
6248

6349
void _dispatch_runloop_queue_dispose() { LINUX_PORT_ERROR(); }
64-
char* mach_error_string(mach_msg_return_t x) {
65-
LINUX_PORT_ERROR();
66-
}
67-
6850
void mach_vm_deallocate() { LINUX_PORT_ERROR(); }
6951

7052
mach_port_t pthread_mach_thread_np() {
71-
return (mach_port_t)pthread_self();
72-
}
73-
74-
mach_port_t mach_task_self() {
75-
return (mach_port_t)pthread_self();
53+
return (pid_t)syscall(SYS_gettid);
7654
}
7755

7856
/*

src/source.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,13 @@ _dispatch_source_kevent_resume(dispatch_source_t ds, uint32_t new_flags)
604604
_dispatch_debug("kevent-source[%p]: rearmed kevent[%p]", ds,
605605
ds->ds_dkev);
606606
return;
607+
#if HAVE_MACH
607608
case EVFILT_MACHPORT:
608609
if (ds->ds_pending_data_mask & DISPATCH_MACH_RECV_MESSAGE) {
609610
new_flags |= DISPATCH_MACH_RECV_MESSAGE; // emulate EV_DISPATCH
610611
}
611612
break;
613+
#endif
612614
}
613615
if ((ds->ds_atomic_flags & DSF_DELETED) ||
614616
_dispatch_kevent_resume(ds->ds_dkev, new_flags, 0)) {
@@ -931,6 +933,7 @@ _dispatch_kevent_hash(uint64_t ident, short filter)
931933
MACH_PORT_INDEX(ident) : ident);
932934
#else
933935
value = ident;
936+
(void)filter;
934937
#endif
935938
return DSL_HASH((uintptr_t)value);
936939
}
@@ -1025,6 +1028,10 @@ _dispatch_kevent_resume(dispatch_kevent_t dk, uint32_t new_flags,
10251028
}
10261029
return r;
10271030
}
1031+
#if !HAVE_MACH
1032+
(void)new_flags;
1033+
(void)del_flags;
1034+
#endif
10281035
}
10291036

10301037
static long
@@ -4766,13 +4773,10 @@ _dispatch_source_debug(dispatch_source_t ds, char* buf, size_t bufsiz)
47664773
return offset;
47674774
}
47684775

4776+
#if HAVE_MACH
47694777
static size_t
47704778
_dispatch_mach_debug_attr(dispatch_mach_t dm, char* buf, size_t bufsiz)
47714779
{
4772-
#ifdef __LINUX_PORT_HDD__
4773-
LINUX_PORT_ERROR();
4774-
return (size_t)0;
4775-
#else
47764780
dispatch_queue_t target = dm->do_targetq;
47774781
return dsnprintf(buf, bufsiz, "target = %s[%p], receive = 0x%x, "
47784782
"send = 0x%x, send-possible = 0x%x%s, checkin = 0x%x%s, "
@@ -4786,15 +4790,10 @@ _dispatch_mach_debug_attr(dispatch_mach_t dm, char* buf, size_t bufsiz)
47864790
dm->dm_refs->dm_checkin ? " (pending)" : "",
47874791
dm->dm_refs->dm_sending, dm->dm_refs->dm_disconnect_cnt,
47884792
(bool)(dm->ds_atomic_flags & DSF_CANCELED));
4789-
#endif
47904793
}
47914794
size_t
47924795
_dispatch_mach_debug(dispatch_mach_t dm, char* buf, size_t bufsiz)
47934796
{
4794-
#ifdef __LINUX_PORT_HDD__
4795-
LINUX_PORT_ERROR();
4796-
return (size_t)0;
4797-
#else
47984797
size_t offset = 0;
47994798
offset += dsnprintf(&buf[offset], bufsiz - offset, "%s[%p] = { ",
48004799
dm->dq_label && !dm->dm_cancel_handler_called ? dm->dq_label :
@@ -4803,8 +4802,8 @@ _dispatch_mach_debug(dispatch_mach_t dm, char* buf, size_t bufsiz)
48034802
offset += _dispatch_mach_debug_attr(dm, &buf[offset], bufsiz - offset);
48044803
offset += dsnprintf(&buf[offset], bufsiz - offset, "}");
48054804
return offset;
4806-
#endif
48074805
}
4806+
#endif
48084807

48094808
#if DISPATCH_DEBUG
48104809
DISPATCH_NOINLINE

src/source_internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#define DISPATCH_EVFILT_MACH_NOTIFICATION (-EVFILT_SYSCOUNT - 4)
3939
#define DISPATCH_EVFILT_SYSCOUNT ( EVFILT_SYSCOUNT + 4)
4040

41+
#if HAVE_MACH
4142
// NOTE: dispatch_source_mach_send_flags_t and dispatch_source_mach_recv_flags_t
4243
// bit values must not overlap as they share the same kevent fflags !
4344

@@ -68,6 +69,7 @@ enum {
6869
DISPATCH_MACH_RECV_MESSAGE_DIRECT_ONCE = 0x20,
6970
DISPATCH_MACH_RECV_NO_SENDERS = 0x40,
7071
};
72+
#endif
7173

7274
enum {
7375
DISPATCH_TIMER_WALL_CLOCK = 0x4,
@@ -201,6 +203,7 @@ struct dispatch_source_s {
201203
unsigned long ds_pending_data;
202204
};
203205

206+
#if HAVE_MACH
204207
// Mach channel state which may contain references to the channel object
205208
// layout must match dispatch_source_refs_s
206209
struct dispatch_mach_refs_s {
@@ -258,6 +261,7 @@ struct dispatch_mach_msg_s {
258261
char dmsg_buf[0];
259262
};
260263
};
264+
#endif
261265

262266
#if TARGET_OS_EMBEDDED
263267
#define DSL_HASH_SIZE 64u // must be a power of two
@@ -275,6 +279,7 @@ void _dispatch_source_set_interval(dispatch_source_t ds, uint64_t interval);
275279
void _dispatch_source_set_event_handler_with_context_f(dispatch_source_t ds,
276280
void *ctxt, dispatch_function_t handler);
277281

282+
#if HAVE_MACH
278283
void _dispatch_mach_dispose(dispatch_mach_t dm);
279284
void _dispatch_mach_invoke(dispatch_mach_t dm, dispatch_object_t dou,
280285
dispatch_invoke_flags_t flags);
@@ -287,6 +292,7 @@ void _dispatch_mach_msg_invoke(dispatch_mach_msg_t dmsg, dispatch_object_t dou,
287292
size_t _dispatch_mach_msg_debug(dispatch_mach_msg_t dmsg, char* buf, size_t bufsiz);
288293

289294
void _dispatch_mach_barrier_invoke(void *ctxt);
295+
#endif
290296

291297
unsigned long _dispatch_mgr_wakeup(dispatch_queue_t dq);
292298
void _dispatch_mgr_thread(dispatch_queue_t dq, dispatch_object_t dou,

0 commit comments

Comments
 (0)