Skip to content

Commit 3339b81

Browse files
authoredJun 18, 2016
Merge pull request swiftlang#86 from dgrove-oss/kill_mach_task_self_on_linux
eliminate mach_task_self from linux_stubs
2 parents 9f1e778 + 92ff1bf commit 3339b81

File tree

5 files changed

+17
-26
lines changed

5 files changed

+17
-26
lines changed
 

‎src/data.c

+2
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@ _dispatch_data_destroy_buffer(const void* buffer, size_t size,
155155
free((void*)buffer);
156156
} else if (destructor == DISPATCH_DATA_DESTRUCTOR_NONE) {
157157
// do nothing
158+
#if HAVE_MACH
158159
} else if (destructor == DISPATCH_DATA_DESTRUCTOR_VM_DEALLOCATE) {
159160
mach_vm_size_t vm_size = size;
160161
mach_vm_address_t vm_addr = (uintptr_t)buffer;
161162
mach_vm_deallocate(mach_task_self(), vm_addr, vm_size);
163+
#endif
162164
} else {
163165
if (!queue) {
164166
queue = dispatch_get_global_queue(

‎src/init.c

+2
Original file line numberDiff line numberDiff line change
@@ -580,12 +580,14 @@ _dispatch_bug_client(const char* msg)
580580
_dispatch_bug_log("BUG in libdispatch client: %s", msg);
581581
}
582582

583+
#if HAVE_MACH
583584
void
584585
_dispatch_bug_mach_client(const char* msg, mach_msg_return_t kr)
585586
{
586587
_dispatch_bug_log("BUG in libdispatch client: %s %s - 0x%x", msg,
587588
mach_error_string(kr), kr);
588589
}
590+
#endif
589591

590592
void
591593
_dispatch_bug_kevent_client(const char* msg, const char* filter,

‎src/queue.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ dispatch_assert_queue(dispatch_queue_t dq)
553553
if (unlikely(_dq_state_drain_pended(dq_state))) {
554554
goto fail;
555555
}
556-
if (likely(_dq_state_drain_owner(dq_state) == _dispatch_thread_port())) {
556+
if (likely(_dq_state_drain_owner(dq_state) == _dispatch_tid_self())) {
557557
return;
558558
}
559559
if (likely(dq->dq_width > 1)) {
@@ -580,7 +580,7 @@ dispatch_assert_queue_not(dispatch_queue_t dq)
580580
if (_dq_state_drain_pended(dq_state)) {
581581
return;
582582
}
583-
if (likely(_dq_state_drain_owner(dq_state) != _dispatch_thread_port())) {
583+
if (likely(_dq_state_drain_owner(dq_state) != _dispatch_tid_self())) {
584584
if (likely(dq->dq_width == 1)) {
585585
// we can look at the width: if it is changing while we read it,
586586
// it means that a barrier is running on `dq` concurrently, which
@@ -1602,7 +1602,7 @@ _dispatch_queue_resume(dispatch_queue_t dq, bool activate)
16021602
DISPATCH_QUEUE_WIDTH_FULL_BIT) {
16031603
value = full_width;
16041604
value &= ~DISPATCH_QUEUE_DIRTY;
1605-
value |= _dispatch_thread_port();
1605+
value |= _dispatch_tid_self();
16061606
}
16071607
}
16081608
}
@@ -2334,7 +2334,7 @@ _dispatch_queue_is_exclusively_owned_by_current_thread_4IOHID(
23342334
DISPATCH_CLIENT_CRASH(dq->dq_width, "Invalid queue type");
23352335
}
23362336
uint64_t dq_state = os_atomic_load2o(dq, dq_state, relaxed);
2337-
return _dq_state_drain_locked_by(dq_state, _dispatch_thread_port());
2337+
return _dq_state_drain_locked_by(dq_state, _dispatch_tid_self());
23382338
}
23392339
#endif
23402340

@@ -2471,7 +2471,7 @@ _dispatch_set_priority_and_mach_voucher_slow(pthread_priority_t pp,
24712471
pflags |= _PTHREAD_SET_SELF_QOS_FLAG;
24722472
}
24732473
if (unlikely(DISPATCH_QUEUE_DRAIN_OWNER(&_dispatch_mgr_q) ==
2474-
_dispatch_thread_port())) {
2474+
_dispatch_tid_self())) {
24752475
DISPATCH_INTERNAL_CRASH(pp,
24762476
"Changing the QoS while on the manager queue");
24772477
}
@@ -2775,7 +2775,7 @@ _dispatch_block_invoke_direct(const struct dispatch_block_private_data_s *dbcpd)
27752775
v = dbpd->dbpd_voucher;
27762776
}
27772777
ov = _dispatch_adopt_priority_and_set_voucher(p, v, adopt_flags);
2778-
dbpd->dbpd_thread = _dispatch_thread_port();
2778+
dbpd->dbpd_thread = _dispatch_tid_self();
27792779
_dispatch_client_callout(dbpd->dbpd_block,
27802780
_dispatch_Block_invoke(dbpd->dbpd_block));
27812781
_dispatch_reset_priority_and_voucher(op, ov);
@@ -3125,7 +3125,7 @@ _dispatch_async_redirect_invoke(dispatch_continuation_t dc,
31253125
old_dp = _dispatch_set_defaultpriority(dq->dq_priority, &dp);
31263126
op = dq->dq_override;
31273127
if (op > (dp & _PTHREAD_PRIORITY_QOS_CLASS_MASK)) {
3128-
_dispatch_wqthread_override_start(_dispatch_thread_port(), op);
3128+
_dispatch_wqthread_override_start(_dispatch_tid_self(), op);
31293129
// Ensure that the root queue sees that this thread was overridden.
31303130
_dispatch_set_defaultpriority_override();
31313131
}
@@ -3545,7 +3545,7 @@ _dispatch_barrier_sync_f_slow(dispatch_queue_t dq, void *ctxt,
35453545
_dispatch_introspection_barrier_sync_begin(dq, func);
35463546
}
35473547
#endif
3548-
uint32_t th_self = _dispatch_thread_port();
3548+
uint32_t th_self = _dispatch_tid_self();
35493549
struct dispatch_continuation_s dbss = {
35503550
.dc_flags = DISPATCH_OBJ_BARRIER_BIT | DISPATCH_OBJ_SYNC_SLOW_BIT,
35513551
.dc_func = _dispatch_barrier_sync_f_slow_invoke,
@@ -3711,7 +3711,7 @@ _dispatch_non_barrier_complete(dispatch_queue_t dq)
37113711
DISPATCH_QUEUE_WIDTH_FULL_BIT) {
37123712
new_state = full_width;
37133713
new_state &= ~DISPATCH_QUEUE_DIRTY;
3714-
new_state |= _dispatch_thread_port();
3714+
new_state |= _dispatch_tid_self();
37153715
}
37163716
}
37173717
}
@@ -3738,7 +3738,7 @@ _dispatch_sync_f_slow(dispatch_queue_t dq, void *ctxt, dispatch_function_t func,
37383738
}
37393739
dispatch_thread_event_s event;
37403740
_dispatch_thread_event_init(&event);
3741-
uint32_t th_self = _dispatch_thread_port();
3741+
uint32_t th_self = _dispatch_tid_self();
37423742
struct dispatch_continuation_s dc = {
37433743
.dc_flags = DISPATCH_OBJ_SYNC_SLOW_BIT,
37443744
#if DISPATCH_INTROSPECTION
@@ -4438,7 +4438,7 @@ _dispatch_main_queue_drain(void)
44384438
" after dispatch_main()");
44394439
}
44404440
mach_port_t owner = DISPATCH_QUEUE_DRAIN_OWNER(dq);
4441-
if (slowpath(owner != _dispatch_thread_port())) {
4441+
if (slowpath(owner != _dispatch_tid_self())) {
44424442
DISPATCH_CLIENT_CRASH(owner, "_dispatch_main_queue_callback_4CF called"
44434443
" from the wrong thread");
44444444
}
@@ -4663,7 +4663,7 @@ _dispatch_queue_drain_deferred_invoke(dispatch_queue_t dq,
46634663
}
46644664

46654665
if (dq) {
4666-
uint32_t self = _dispatch_thread_port();
4666+
uint32_t self = _dispatch_tid_self();
46674667
os_atomic_rmw_loop2o(dq, dq_state, old_state, new_state, release,{
46684668
new_state = old_state;
46694669
if (!_dq_state_drain_pended(old_state) ||
@@ -5094,7 +5094,7 @@ _dispatch_queue_class_wakeup(dispatch_queue_t dq, pthread_priority_t pp,
50945094
uint64_t pending_barrier_width =
50955095
(dq->dq_width - 1) * DISPATCH_QUEUE_WIDTH_INTERVAL;
50965096
uint64_t xor_owner_and_set_full_width_and_in_barrier =
5097-
_dispatch_thread_port() | DISPATCH_QUEUE_WIDTH_FULL_BIT |
5097+
_dispatch_tid_self() | DISPATCH_QUEUE_WIDTH_FULL_BIT |
50985098
DISPATCH_QUEUE_IN_BARRIER;
50995099

51005100
#ifdef DLOCK_NOWAITERS_BIT

‎src/shims/linux_stubs.c

-11
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,6 @@ unsigned long _dispatch_runloop_queue_probe(dispatch_queue_t dq) {
3939
void _dispatch_runloop_queue_xref_dispose() { LINUX_PORT_ERROR(); }
4040

4141
void _dispatch_runloop_queue_dispose() { LINUX_PORT_ERROR(); }
42-
char* mach_error_string(mach_msg_return_t x) {
43-
LINUX_PORT_ERROR();
44-
}
45-
void mach_vm_deallocate() { LINUX_PORT_ERROR(); }
46-
47-
mach_port_t pthread_mach_thread_np(void) {
48-
return (pid_t)syscall(SYS_gettid);
49-
}
50-
mach_port_t mach_task_self(void) {
51-
return (mach_port_t)pthread_self();
52-
}
5342

5443
/*
5544
* Stubbed out static data

‎src/shims/linux_stubs.h

-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ typedef void (*dispatch_mach_handler_function_t)(void*, dispatch_mach_reason_t,
6262

6363
typedef void (*dispatch_mach_msg_destructor_t)(void*);
6464

65-
mach_port_t mach_task_self();
66-
6765
// Print a warning when an unported code path executes.
6866
#define LINUX_PORT_ERROR() do { printf("LINUX_PORT_ERROR_CALLED %s:%d: %s\n",__FILE__,__LINE__,__FUNCTION__); } while (0)
6967

0 commit comments

Comments
 (0)
Please sign in to comment.