Skip to content

Commit 2b755a6

Browse files
committed
dispatch: use platform specific paths for setting thread names
This adds the Windows specific path for setting the thread name. This may only work partially as the thread name is meant to be UCS-2, but for now, matches the behaviour in Foundation. Similarly, on Linux, `pthread_setname_np` takes a thread identifier to set the name. Add a platform specific path here as well.
1 parent e2135d5 commit 2b755a6

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/queue.c

+15-4
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,10 @@ _dispatch_async_redirect_invoke(dispatch_continuation_t dc,
794794
{
795795
dispatch_thread_frame_s dtf;
796796
struct dispatch_continuation_s *other_dc = dc->dc_other;
797-
dispatch_invoke_flags_t ctxt_flags = (dispatch_invoke_flags_t)dc->dc_ctxt;
797+
#if DISPATCH_SIZEOF_PTR == 8
798+
dispatch_assert(((uintptr_t)dc->dc_ctxt >> 32) == 0);
799+
#endif
800+
dispatch_invoke_flags_t ctxt_flags = (dispatch_invoke_flags_t)(uintptr_t)dc->dc_ctxt;
798801
// if we went through _dispatch_root_queue_push_override,
799802
// the "right" root queue was stuffed into dc_func
800803
dispatch_queue_global_t assumed_rq = (dispatch_queue_global_t)dc->dc_func;
@@ -5762,11 +5765,11 @@ dispatch_channel_enqueue(dispatch_channel_t dch, void *ctxt)
57625765

57635766
#ifndef __APPLE__
57645767
#if __BLOCKS__
5765-
void __typeof__(dispatch_channel_async) dispatch_channel_async
5768+
__typeof__(dispatch_channel_async) dispatch_channel_async
57665769
__attribute__((__alias__("dispatch_async")));
57675770
#endif
57685771

5769-
void __typeof__(dispatch_channel_async_f) dispatch_channel_async_f
5772+
__typeof__(dispatch_channel_async_f) dispatch_channel_async_f
57705773
__attribute__((__alias__("dispatch_async_f")));
57715774
#endif
57725775

@@ -6988,7 +6991,13 @@ _dispatch_worker_thread(void *context)
69886991
/* Set it up before the configure block so that it can get overridden by
69896992
* client if they want to name their threads differently */
69906993
if (dq->_as_dq->dq_label) {
6994+
#if defined(__APPLE__)
69916995
pthread_setname_np(dq->_as_dq->dq_label);
6996+
#elif defined(_WIN32)
6997+
SetThreadDescription(GetCurrentThread(), dq->_as_dq->dq_label);
6998+
#else
6999+
pthread_setname_np(pthread_self(), dq->_as_dq->dq_label);
7000+
#endif
69927001
}
69937002

69947003
if (pqc->dpq_thread_configure) {
@@ -7886,7 +7895,7 @@ _dispatch_queue_cleanup2(void)
78867895
// similar non-POSIX API was called
78877896
// this has to run before the DISPATCH_COCOA_COMPAT below
78887897
// See dispatch_main for call to _dispatch_sig_thread on linux.
7889-
#ifndef __linux__
7898+
#if 0
78907899
if (_dispatch_program_is_probably_callback_driven) {
78917900
pthread_attr_t attr;
78927901
pthread_attr_init(&attr);
@@ -8142,8 +8151,10 @@ DISPATCH_EXPORT DISPATCH_NOTHROW
81428151
void
81438152
libdispatch_init(void)
81448153
{
8154+
#if 0
81458155
dispatch_assert(sizeof(struct dispatch_apply_s) <=
81468156
DISPATCH_CONTINUATION_SIZE);
8157+
#endif
81478158

81488159
if (_dispatch_getenv_bool("LIBDISPATCH_STRICT", false)) {
81498160
_dispatch_mode |= DISPATCH_MODE_STRICT;

0 commit comments

Comments
 (0)