Skip to content

Commit e358313

Browse files
committed
event: attempt to support workqueue monitoring on Windows
This adds a poor approximation for the thread counting support. This hopefully enables some level of overcommit support for Dispatch root queues. Enabling proper support for overcommit should resolve the recent hangs with package resolution.
1 parent ceabeea commit e358313

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/event/workqueue.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,34 @@ _dispatch_workq_count_runnable_workers(dispatch_workq_monitor_t mon)
180180

181181
_dispatch_unfair_lock_unlock(&mon->registered_tid_lock);
182182
}
183+
#elif defined(_WIN32)
184+
static void
185+
_dispatch_workq_count_runnable_workers(dispatch_workq_monitor_t mon)
186+
{
187+
int running_count = 0;
188+
189+
_dispatch_unfair_lock_lock(&mon->registered_tid_lock);
190+
191+
for (int i = 0; i < mon->num_registered_tids; ++i) {
192+
dispatch_tid tid = mon->registered_tids[i];
193+
HANDLE hThread = OpenThread(THREAD_QUERY_INFORMATION, FALSE, tid);
194+
if (hThread == NULL) {
195+
_dispatch_debug("workq: unable to open thread %u: %u", tid, GetLastError());
196+
continue;
197+
}
198+
199+
BOOL IOPending = TRUE;
200+
if (GetThreadIOPendingFlag(hThread, &IOPending))
201+
if (!IOPending)
202+
++running_count;
203+
204+
CloseHandle(hThread);
205+
}
206+
207+
mon->num_runnable = running_count;
208+
209+
_dispatch_unfair_lock_unlock(&mon->registered_tid_lock);
210+
}
183211
#else
184212
#error must define _dispatch_workq_count_runnable_workers
185213
#endif

src/event/workqueue_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
void _dispatch_workq_worker_register(dispatch_queue_global_t root_q);
3131
void _dispatch_workq_worker_unregister(dispatch_queue_global_t root_q);
3232

33-
#if defined(__linux__)
33+
#if defined(__linux__) || defined(_WIN32)
3434
#define HAVE_DISPATCH_WORKQ_MONITORING 1
3535
#else
3636
#define HAVE_DISPATCH_WORKQ_MONITORING 0

0 commit comments

Comments
 (0)