Skip to content

eliminate mach_task_self from linux_stubs #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,12 @@ _dispatch_data_destroy_buffer(const void* buffer, size_t size,
free((void*)buffer);
} else if (destructor == DISPATCH_DATA_DESTRUCTOR_NONE) {
// do nothing
#if HAVE_MACH
} else if (destructor == DISPATCH_DATA_DESTRUCTOR_VM_DEALLOCATE) {
mach_vm_size_t vm_size = size;
mach_vm_address_t vm_addr = (uintptr_t)buffer;
mach_vm_deallocate(mach_task_self(), vm_addr, vm_size);
#endif
} else {
if (!queue) {
queue = dispatch_get_global_queue(
Expand Down
2 changes: 2 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,12 +580,14 @@ _dispatch_bug_client(const char* msg)
_dispatch_bug_log("BUG in libdispatch client: %s", msg);
}

#if HAVE_MACH
void
_dispatch_bug_mach_client(const char* msg, mach_msg_return_t kr)
{
_dispatch_bug_log("BUG in libdispatch client: %s %s - 0x%x", msg,
mach_error_string(kr), kr);
}
#endif

void
_dispatch_bug_kevent_client(const char* msg, const char* filter,
Expand Down
26 changes: 13 additions & 13 deletions src/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ dispatch_assert_queue(dispatch_queue_t dq)
if (unlikely(_dq_state_drain_pended(dq_state))) {
goto fail;
}
if (likely(_dq_state_drain_owner(dq_state) == _dispatch_thread_port())) {
if (likely(_dq_state_drain_owner(dq_state) == _dispatch_tid_self())) {
return;
}
if (likely(dq->dq_width > 1)) {
Expand All @@ -580,7 +580,7 @@ dispatch_assert_queue_not(dispatch_queue_t dq)
if (_dq_state_drain_pended(dq_state)) {
return;
}
if (likely(_dq_state_drain_owner(dq_state) != _dispatch_thread_port())) {
if (likely(_dq_state_drain_owner(dq_state) != _dispatch_tid_self())) {
if (likely(dq->dq_width == 1)) {
// we can look at the width: if it is changing while we read it,
// it means that a barrier is running on `dq` concurrently, which
Expand Down Expand Up @@ -1602,7 +1602,7 @@ _dispatch_queue_resume(dispatch_queue_t dq, bool activate)
DISPATCH_QUEUE_WIDTH_FULL_BIT) {
value = full_width;
value &= ~DISPATCH_QUEUE_DIRTY;
value |= _dispatch_thread_port();
value |= _dispatch_tid_self();
}
}
}
Expand Down Expand Up @@ -2334,7 +2334,7 @@ _dispatch_queue_is_exclusively_owned_by_current_thread_4IOHID(
DISPATCH_CLIENT_CRASH(dq->dq_width, "Invalid queue type");
}
uint64_t dq_state = os_atomic_load2o(dq, dq_state, relaxed);
return _dq_state_drain_locked_by(dq_state, _dispatch_thread_port());
return _dq_state_drain_locked_by(dq_state, _dispatch_tid_self());
}
#endif

Expand Down Expand Up @@ -2471,7 +2471,7 @@ _dispatch_set_priority_and_mach_voucher_slow(pthread_priority_t pp,
pflags |= _PTHREAD_SET_SELF_QOS_FLAG;
}
if (unlikely(DISPATCH_QUEUE_DRAIN_OWNER(&_dispatch_mgr_q) ==
_dispatch_thread_port())) {
_dispatch_tid_self())) {
DISPATCH_INTERNAL_CRASH(pp,
"Changing the QoS while on the manager queue");
}
Expand Down Expand Up @@ -2775,7 +2775,7 @@ _dispatch_block_invoke_direct(const struct dispatch_block_private_data_s *dbcpd)
v = dbpd->dbpd_voucher;
}
ov = _dispatch_adopt_priority_and_set_voucher(p, v, adopt_flags);
dbpd->dbpd_thread = _dispatch_thread_port();
dbpd->dbpd_thread = _dispatch_tid_self();
_dispatch_client_callout(dbpd->dbpd_block,
_dispatch_Block_invoke(dbpd->dbpd_block));
_dispatch_reset_priority_and_voucher(op, ov);
Expand Down Expand Up @@ -3125,7 +3125,7 @@ _dispatch_async_redirect_invoke(dispatch_continuation_t dc,
old_dp = _dispatch_set_defaultpriority(dq->dq_priority, &dp);
op = dq->dq_override;
if (op > (dp & _PTHREAD_PRIORITY_QOS_CLASS_MASK)) {
_dispatch_wqthread_override_start(_dispatch_thread_port(), op);
_dispatch_wqthread_override_start(_dispatch_tid_self(), op);
// Ensure that the root queue sees that this thread was overridden.
_dispatch_set_defaultpriority_override();
}
Expand Down Expand Up @@ -3545,7 +3545,7 @@ _dispatch_barrier_sync_f_slow(dispatch_queue_t dq, void *ctxt,
_dispatch_introspection_barrier_sync_begin(dq, func);
}
#endif
uint32_t th_self = _dispatch_thread_port();
uint32_t th_self = _dispatch_tid_self();
struct dispatch_continuation_s dbss = {
.dc_flags = DISPATCH_OBJ_BARRIER_BIT | DISPATCH_OBJ_SYNC_SLOW_BIT,
.dc_func = _dispatch_barrier_sync_f_slow_invoke,
Expand Down Expand Up @@ -3711,7 +3711,7 @@ _dispatch_non_barrier_complete(dispatch_queue_t dq)
DISPATCH_QUEUE_WIDTH_FULL_BIT) {
new_state = full_width;
new_state &= ~DISPATCH_QUEUE_DIRTY;
new_state |= _dispatch_thread_port();
new_state |= _dispatch_tid_self();
}
}
}
Expand All @@ -3738,7 +3738,7 @@ _dispatch_sync_f_slow(dispatch_queue_t dq, void *ctxt, dispatch_function_t func,
}
dispatch_thread_event_s event;
_dispatch_thread_event_init(&event);
uint32_t th_self = _dispatch_thread_port();
uint32_t th_self = _dispatch_tid_self();
struct dispatch_continuation_s dc = {
.dc_flags = DISPATCH_OBJ_SYNC_SLOW_BIT,
#if DISPATCH_INTROSPECTION
Expand Down Expand Up @@ -4438,7 +4438,7 @@ _dispatch_main_queue_drain(void)
" after dispatch_main()");
}
mach_port_t owner = DISPATCH_QUEUE_DRAIN_OWNER(dq);
if (slowpath(owner != _dispatch_thread_port())) {
if (slowpath(owner != _dispatch_tid_self())) {
DISPATCH_CLIENT_CRASH(owner, "_dispatch_main_queue_callback_4CF called"
" from the wrong thread");
}
Expand Down Expand Up @@ -4663,7 +4663,7 @@ _dispatch_queue_drain_deferred_invoke(dispatch_queue_t dq,
}

if (dq) {
uint32_t self = _dispatch_thread_port();
uint32_t self = _dispatch_tid_self();
os_atomic_rmw_loop2o(dq, dq_state, old_state, new_state, release,{
new_state = old_state;
if (!_dq_state_drain_pended(old_state) ||
Expand Down Expand Up @@ -5094,7 +5094,7 @@ _dispatch_queue_class_wakeup(dispatch_queue_t dq, pthread_priority_t pp,
uint64_t pending_barrier_width =
(dq->dq_width - 1) * DISPATCH_QUEUE_WIDTH_INTERVAL;
uint64_t xor_owner_and_set_full_width_and_in_barrier =
_dispatch_thread_port() | DISPATCH_QUEUE_WIDTH_FULL_BIT |
_dispatch_tid_self() | DISPATCH_QUEUE_WIDTH_FULL_BIT |
DISPATCH_QUEUE_IN_BARRIER;

#ifdef DLOCK_NOWAITERS_BIT
Expand Down
11 changes: 0 additions & 11 deletions src/shims/linux_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@ unsigned long _dispatch_runloop_queue_probe(dispatch_queue_t dq) {
void _dispatch_runloop_queue_xref_dispose() { LINUX_PORT_ERROR(); }

void _dispatch_runloop_queue_dispose() { LINUX_PORT_ERROR(); }
char* mach_error_string(mach_msg_return_t x) {
LINUX_PORT_ERROR();
}
void mach_vm_deallocate() { LINUX_PORT_ERROR(); }

mach_port_t pthread_mach_thread_np(void) {
return (pid_t)syscall(SYS_gettid);
}
mach_port_t mach_task_self(void) {
return (mach_port_t)pthread_self();
}

/*
* Stubbed out static data
Expand Down
2 changes: 0 additions & 2 deletions src/shims/linux_stubs.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ typedef void (*dispatch_mach_handler_function_t)(void*, dispatch_mach_reason_t,

typedef void (*dispatch_mach_msg_destructor_t)(void*);

mach_port_t mach_task_self();

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

Expand Down