Skip to content

Commit 0bc1ee2

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 956c270 commit 0bc1ee2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/queue.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6988,7 +6988,19 @@ _dispatch_worker_thread(void *context)
69886988
/* Set it up before the configure block so that it can get overridden by
69896989
* client if they want to name their threads differently */
69906990
if (dq->_as_dq->dq_label) {
6991+
#if defined(__APPLE__)
69916992
pthread_setname_np(dq->_as_dq->dq_label);
6993+
#elif defined(_WIN32)
6994+
int length = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, dq->_as_dq->dq_label, -1, NULL, 0);
6995+
if (length) {
6996+
WCHAR *description = calloc(length + 1, sizeof(WCHAR));
6997+
MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, dq->_as_dq->dq_label, -1, description, length);
6998+
SetThreadDescription(GetCurrentThread(), description);
6999+
free(description);
7000+
}
7001+
#else
7002+
pthread_setname_np(pthread_self(), dq->_as_dq->dq_label);
7003+
#endif
69927004
}
69937005

69947006
if (pqc->dpq_thread_configure) {

0 commit comments

Comments
 (0)