Commit 6d712a42 authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

ntdll: Increment num_busy_workers when queuing TP object.

Otherwise two consequative submits may have the same num_busy_workers value if threadpool_worker_proc did not have a chance to pick the work in between. A new thread is not created in tp_submit() for the second submit and if the first submit queues an (infinitely long) wait the next submitted callback is not called for indefinite time period. Fixes hang on exit in Detroit Become Human. Signed-off-by: 's avatarPaul Gofman <pgofman@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 46eac8de
......@@ -1375,7 +1375,6 @@ static NTSTATUS tp_new_worker_thread( struct threadpool *pool )
{
InterlockedIncrement( &pool->refcount );
pool->num_workers++;
pool->num_busy_workers++;
NtClose( thread );
}
return status;
......@@ -2137,6 +2136,7 @@ static void tp_object_initialize( struct threadpool_object *object, struct threa
static void tp_object_prio_queue( struct threadpool_object *object )
{
++object->pool->num_busy_workers;
list_add_tail( &object->pool->pools[object->priority], &object->pool_entry );
}
......@@ -2330,7 +2330,6 @@ static void CALLBACK threadpool_worker_proc( void *param )
TRACE( "starting worker thread for pool %p\n", pool );
RtlEnterCriticalSection( &pool->cs );
pool->num_busy_workers--;
for (;;)
{
while ((ptr = threadpool_get_next_item( pool )))
......@@ -2360,7 +2359,6 @@ static void CALLBACK threadpool_worker_proc( void *param )
/* Leave critical section and do the actual callback. */
object->num_associated_callbacks++;
object->num_running_callbacks++;
pool->num_busy_workers++;
RtlLeaveCriticalSection( &pool->cs );
/* Initialize threadpool instance struct. */
......@@ -2466,6 +2464,7 @@ static void CALLBACK threadpool_worker_proc( void *param )
skip_cleanup:
RtlEnterCriticalSection( &pool->cs );
assert(pool->num_busy_workers);
pool->num_busy_workers--;
/* Simple callbacks are automatically shutdown after execution. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment